package com.iplant.pdm.serviceImpl;

import com.iplant.ams.service.po.ams.fxt.AMSFrockTool;
import com.iplant.ams.service.po.ams.fxt.AMSMeasureTool;
import com.iplant.base.po.*;
import com.iplant.base.po.excel.ExcelData;
import com.iplant.base.po.excel.ExcelLineData;
import com.iplant.base.po.excel.ExcelSheetData;
import com.iplant.base.po.excel.MyExcelSheet;
import com.iplant.base.utils.RetCode;
import com.iplant.base.utils.cache.CacheUtils;
import com.iplant.base.utils.serializer.CloneTool;
import com.iplant.base.utils.sql.orm.ORMUtils;
import com.iplant.base.utils.sql.orm.PoService;
import com.iplant.basic.service.basicenum.bfc.FMCShiftType;
import com.iplant.basic.service.po.crm.CRMCustomer;
import com.iplant.basic.service.po.fmc.*;
import com.iplant.basic.service.po.mss.MSSMaterial;
import com.iplant.basic.service.po.mss.MSSUnit;
import com.iplant.basic.utils.ExcelUtil;
import com.iplant.pdm.service.FPCService;
import com.iplant.pdm.service.basicenum.bop.FPCRouteStatus;
import com.iplant.pdm.service.basicenum.fpc.*;
import com.iplant.pdm.service.basicenum.pdm.PDMComponentTypes;
import com.iplant.pdm.service.po.bop.*;
import com.iplant.pdm.service.po.bop.partpoint.*;
import com.iplant.pdm.service.po.fmc.FMCLine;
import com.iplant.pdm.service.po.fpc.*;
import com.iplant.pdm.service.po.fpc.flow.FPCFlowLine;
import com.iplant.pdm.service.po.fpc.flow.FPCFlowPart;
import com.iplant.pdm.service.po.mss.MSSBOMItem;
import com.iplant.pdm.serviceImpl.dao.fpc.*;
import com.iplant.base.po.enums.ExceptionTypes;
import com.iplant.base.utils.general.StringUtils;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.basic.serviceImpl.BMSServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

@Service
public class FPCServiceImpl implements FPCService {
    private static Logger logger = LoggerFactory.getLogger(BMSServiceImpl.class);

    private static FPCService _Instance;

    public static FPCService getInstance() {
        if (_Instance == null)
            _Instance = new FPCServiceImpl();

        return _Instance;
    }

    public FPCServiceImpl() {
    }

    //region POService
    PoService<FPCRoute> mFPCRouteService = ORMUtils.GetPoService(FPCRoute.class);
    PoService<FPCRoutePart> mFPCRoutePartService = ORMUtils.GetPoService(FPCRoutePart.class);
    PoService<FPCRoutePartPoint> mFPCRoutePartPointService = ORMUtils.GetPoService(FPCRoutePartPoint.class);
    PoService<FPCRouteStep> mFPCRouteStepService = ORMUtils.GetPoService(FPCRouteStep.class);
    PoService<FPCRouteParent> mFPCRouteParentService = ORMUtils.GetPoService(FPCRouteParent.class);
    PoService<FPCRouteBPM> mFPCRouteBPMService = ORMUtils.GetPoService(FPCRouteBPM.class);
    PoService<FPCRouteFrockTool> mFPCRouteFrockToolService = ORMUtils.GetPoService(FPCRouteFrockTool.class);
    PoService<FPCRouteMeasureTool> mFPCRouteMeasureToolService = ORMUtils.GetPoService(FPCRouteMeasureTool.class);
    PoService<FPCRoutePartPointParameter> mFPCRoutePartPointParameterService =
            ORMUtils.GetPoService(FPCRoutePartPointParameter.class);
    PoService<MSSBOMItem> mMSSBOMItemService = ORMUtils.GetPoService(MSSBOMItem.class);
    PoService<FPCRouteStepQualification> mFPCRouteStepQualificationService =
            ORMUtils.GetPoService(FPCRouteStepQualification.class);
    PoService<FPCProductGroup> mFPCProductGroupService = ORMUtils.GetPoService(FPCProductGroup.class);
    PoService<FPCProductType> mFPCProductTypeService = ORMUtils.GetPoService(FPCProductType.class);
    PoService<FPCProduct> mFPCProductService = ORMUtils.GetPoService(FPCProduct.class);
    PoService<FMCLine> mFMCLineService = ORMUtils.GetPoService(FMCLine.class);
    PoService<CRMCustomer> mCRMCustomerService = ORMUtils.GetPoService(CRMCustomer.class);
    PoService<FMCWorkArea> mFMCWorkAreaService = ORMUtils.GetPoService(FMCWorkArea.class);
    PoService<FMCStation> mFMCStationService = ORMUtils.GetPoService(FMCStation.class);
    PoService<FPCProductParameter> mFPCProductParameterService = ORMUtils.GetPoService(FPCProductParameter.class);
    PoService<MSSMaterial> mMSSMaterialService = ORMUtils.GetPoService(MSSMaterial.class);
    PoService<AMSFrockTool> mAMSFrockToolService = ORMUtils.GetPoService(AMSFrockTool.class);
    PoService<AMSMeasureTool> mAMSMeasureToolService = ORMUtils.GetPoService(AMSMeasureTool.class);
    PoService<MSSUnit> mMSSUnitService = ORMUtils.GetPoService(MSSUnit.class);
    //endregion

    //region 老接口

    @Override
    public ServiceResult<List<FPCCapacity>> FPC_CreateCapacityList(BMSEmployee wLoginUser, int wProductID,
                                                                   int wFactoryID, int wWorkshopID, int wWorkAreaID,
                                                                   int wStationID) {
        ServiceResult<List<FPCCapacity>> wResult = new ServiceResult<List<FPCCapacity>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);

            Map<String, Object> wParams = new HashMap<>();
            wParams.put("FactoryID", wFactoryID);
            wParams.put("WorkshopID", wWorkshopID);
            wParams.put("WorkAreaID", wWorkAreaID);
            wParams.put("StationID", wStationID);
            wParams.put("ProductID", wProductID);

            Map<Integer, FPCCapacity> wFPCCapacityMap = new HashMap<>();


            wResult.Result = FPCCapacityDAO.getInstance().SelectPOList(wLoginUser, wParams, FPCCapacity.class,
                    Pagination.Create(1, Integer.MAX_VALUE, FPCCapacity.class), wErrorCode);

            if (wErrorCode.Result != 0) {
                wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
                return wResult;
            }
            if (wResult.Result != null && wResult.Result.size() > 0) {
                for (FPCCapacity wFPCCapacityT : wResult.Result) {
                    if (wFPCCapacityMap.containsKey(wFPCCapacityT.ShiftType))
                        continue;
                    wFPCCapacityMap.put(wFPCCapacityT.ShiftType, wFPCCapacityT);
                }
                if (wFPCCapacityMap.size() >= FMCShiftType.values().length - 1) {
                    wResult.Result =
                            wFPCCapacityMap.values().stream().sorted((o1, o2) -> o1.ShiftType - o2.ShiftType).collect(Collectors.toList());
                    return wResult;
                }
            }


            //如果是工位，查工区
            if (wStationID > 0) {
                //查询单台工位

                FMCStation wFMCStation = CacheUtils.GetCacheInfo(FMCStation.class, wStationID, "");
                if (wErrorCode.Result != 0) {
                    wResult.AddFaultCode(wErrorCode);
                    return wResult;
                }
                if (wFMCStation == null || wFMCStation.ID <= 0) {
                    wResult.FaultCode += StringUtils.Format("工位ID:{0}不存在！", wStationID);
                    return wResult;
                }
                wParams.clear();
                wFactoryID = wFMCStation.FactoryID;
                wWorkshopID = wFMCStation.WorkshopID;
                wWorkAreaID = wFMCStation.WorkAreaID;

                wParams.put("ProductID", wProductID);
                wParams.put("FactoryID", wFactoryID);
                wParams.put("WorkshopID", wWorkshopID);
                wParams.put("WorkAreaID", wWorkAreaID);
                wParams.put("StationID", 0);

                wResult.Result = FPCCapacityDAO.getInstance().SelectPOList(wLoginUser, wParams, FPCCapacity.class,
                        Pagination.Create(1, Integer.MAX_VALUE, FPCCapacity.class), wErrorCode);
                if (wErrorCode.Result != 0) {
                    wResult.AddFaultCode(wErrorCode);
                    return wResult;
                }
                if (wResult.Result != null) {
                    for (FPCCapacity wFPCCapacity : wResult.Result) {
                        wFPCCapacity.ID = 0;
                        wFPCCapacity.StationID = wStationID;

                        if (wFPCCapacityMap.containsKey(wFPCCapacity.ShiftType))
                            continue;
                        wFPCCapacityMap.put(wFPCCapacity.ShiftType, wFPCCapacity);
                    }
                    if (wFPCCapacityMap.size() >= FMCShiftType.values().length - 1) {
                        wResult.Result =
                                wFPCCapacityMap.values().stream().sorted((o1, o2) -> o1.ShiftType - o2.ShiftType).collect(Collectors.toList());
                        return wResult;
                    }
                }
            }
            //如果是工位，查工区
            if (wWorkAreaID > 0) {
                //查询单台工位
                FMCWorkArea wFMCWorkArea = CacheUtils.GetCacheInfo(FMCWorkArea.class, wWorkAreaID, "");
                if (wErrorCode.Result != 0) {
                    wResult.AddFaultCode(wErrorCode);
                    return wResult;
                }
                if (wFMCWorkArea == null || wFMCWorkArea.ID <= 0) {
                    wResult.FaultCode += StringUtils.Format("工区ID:{0}不存在！", wWorkAreaID);
                    return wResult;
                }
                wParams.clear();
                wFactoryID = wFMCWorkArea.FactoryID;
                wWorkshopID = wFMCWorkArea.WorkshopID;

                wParams.put("ProductID", wProductID);
                wParams.put("FactoryID", wFactoryID);
                wParams.put("WorkshopID", wWorkshopID);
                wParams.put("WorkAreaID", 0);
                wParams.put("StationID", 0);

                wResult.Result = FPCCapacityDAO.getInstance().SelectPOList(wLoginUser, wParams, FPCCapacity.class,
                        Pagination.Create(1, Integer.MAX_VALUE, FPCCapacity.class), wErrorCode);
                if (wErrorCode.Result != 0) {
                    wResult.AddFaultCode(wErrorCode);
                    return wResult;
                }
                if (wResult.Result != null) {
                    for (FPCCapacity wFPCCapacity : wResult.Result) {
                        wFPCCapacity.ID = 0;
                        wFPCCapacity.WorkAreaID = wWorkAreaID;
                        if (wStationID > 0) {
                            wFPCCapacity.StationID = wStationID;
                        }
                        if (wFPCCapacityMap.containsKey(wFPCCapacity.ShiftType))
                            continue;
                        wFPCCapacityMap.put(wFPCCapacity.ShiftType, wFPCCapacity);
                    }
                    if (wFPCCapacityMap.size() >= FMCShiftType.values().length - 1) {
                        wResult.Result =
                                wFPCCapacityMap.values().stream().sorted((o1, o2) -> o1.ShiftType - o2.ShiftType).collect(Collectors.toList());
                        return wResult;
                    }
                }

            }
            //如果是车间
            if (wWorkshopID > 0) {
                //查询车间
                FMCWorkshop wFMCWorkshop = CacheUtils.GetCacheInfo(FMCWorkshop.class, wWorkshopID, "");
                if (wErrorCode.Result != 0) {
                    wResult.AddFaultCode(wErrorCode);
                    return wResult;
                }
                if (wFMCWorkshop == null || wFMCWorkshop.ID <= 0) {
                    wResult.FaultCode += StringUtils.Format("车间ID:{0}不存在！", wWorkshopID);
                    return wResult;
                }
                wParams.clear();
                wFactoryID = wFMCWorkshop.FactoryID;

                wParams.put("ProductID", wProductID);
                wParams.put("FactoryID", wFactoryID);
                wParams.put("WorkshopID", 0);
                wParams.put("WorkAreaID", 0);
                wParams.put("StationID", 0);

                wResult.Result = FPCCapacityDAO.getInstance().SelectPOList(wLoginUser, wParams, FPCCapacity.class,
                        Pagination.Create(1, Integer.MAX_VALUE, FPCCapacity.class), wErrorCode);
                if (wErrorCode.Result != 0) {
                    wResult.AddFaultCode(wErrorCode);
                    return wResult;
                }
                if (wResult.Result != null) {
                    for (FPCCapacity wFPCCapacity : wResult.Result) {
                        wFPCCapacity.ID = 0;
                        wFPCCapacity.WorkshopID = wWorkshopID;
                        if (wWorkAreaID > 0) {
                            wFPCCapacity.WorkAreaID = wWorkAreaID;
                        }
                        if (wStationID > 0) {
                            wFPCCapacity.StationID = wStationID;
                        }
                        if (wFPCCapacityMap.containsKey(wFPCCapacity.ShiftType))
                            continue;
                        wFPCCapacityMap.put(wFPCCapacity.ShiftType, wFPCCapacity);
                    }
                    if (wFPCCapacityMap.size() >= FMCShiftType.values().length - 1) {
                        wResult.Result =
                                wFPCCapacityMap.values().stream().sorted((o1, o2) -> o1.ShiftType - o2.ShiftType).collect(Collectors.toList());
                        return wResult;
                    }
                }
            }

            //如果是工厂
            if (wFactoryID > 0) {
                //查询工厂
                FMCFactory wFMCFactory = CacheUtils.GetCacheInfo(FMCFactory.class, wFactoryID, "");
                if (wErrorCode.Result != 0) {
                    wResult.AddFaultCode(wErrorCode);
                    return wResult;
                }
                if (wFMCFactory == null || wFMCFactory.ID <= 0) {
                    wResult.FaultCode += StringUtils.Format("工厂ID:{0}不存在！", wFactoryID);
                    return wResult;
                }
                //创建车间班次
                FPCCapacity wFPCCapacity;
                for (FMCShiftType wFMCShiftType : FMCShiftType.values()) {
                    if (wFMCShiftType.getValue() <= 0)
                        continue;

                    wFPCCapacity = new FPCCapacity();
                    wFPCCapacity.ProductID = wProductID;
                    wFPCCapacity.FactoryID = wFactoryID;
                    wFPCCapacity.WorkshopID = 0;
                    wFPCCapacity.WorkAreaID = 0;
                    wFPCCapacity.StationID = 0;
                    wFPCCapacity.ShiftType = wFMCShiftType.getValue();
                    wFPCCapacity.Active = 0;
                    wFPCCapacity.CapacityNum = 0;
                    wFPCCapacity.setUserInfo(wLoginUser);
                    FPCCapacityDAO.getInstance().UpdatePo(wLoginUser, wFPCCapacity, wErrorCode);
                    if (wErrorCode.Result != 0) {
                        wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
                        return wResult;
                    }
                }

                wParams.clear();
                wFactoryID = wFMCFactory.ID;
                wParams.put("FactoryID", wFactoryID);
                wParams.put("WorkshopID", 0);
                wParams.put("WorkAreaID", 0);
                wParams.put("StationID", 0);
                wParams.put("ProductID", wProductID);

                wResult.Result = FPCCapacityDAO.getInstance().SelectPOList(wLoginUser, wParams, FPCCapacity.class,
                        Pagination.Create(1, Integer.MAX_VALUE, FPCCapacity.class), wErrorCode);
                if (wErrorCode.Result != 0) {
                    wResult.AddFaultCode(wErrorCode);
                    return wResult;
                }
                if (wResult.Result != null) {
                    for (FPCCapacity wFPCCapacityTemp : wResult.Result) {
                        wFPCCapacityTemp.ID = 0;
                        if (wWorkshopID > 0) {
                            wFPCCapacityTemp.WorkshopID = wWorkshopID;
                        }
                        if (wWorkAreaID > 0) {
                            wFPCCapacityTemp.WorkAreaID = wWorkAreaID;
                        }
                        if (wStationID > 0) {
                            wFPCCapacityTemp.StationID = wStationID;
                        }
                        if (wFPCCapacityMap.containsKey(wFPCCapacityTemp.ShiftType))
                            continue;
                        wFPCCapacityMap.put(wFPCCapacityTemp.ShiftType, wFPCCapacityTemp);
                    }
                    if (wFPCCapacityMap.size() >= FMCShiftType.values().length - 1) {
                        wResult.Result =
                                wFPCCapacityMap.values().stream().sorted((o1, o2) -> o1.ShiftType - o2.ShiftType).collect(Collectors.toList());
                        return wResult;
                    }
                } else {
                    wResult.FaultCode += StringUtils.Format("工厂ID:{0}创建产能数据失败！", wFactoryID);
                }
                return wResult;
            } else {
                wResult.FaultCode += RetCode.SERVER_RST_ERROR_OUT;
                return wResult;
            }
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_UpdatePart(BMSEmployee wLoginUser, FPCPart wPart) {
        // TODO Auto-generated method stub
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            FPCPartDAO.getInstance().FPC_UpdatePart(wLoginUser, wPart, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {

            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_DeletePart(BMSEmployee wLoginUser, FPCPart wPart) {
        // TODO Auto-generated method stub
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            FPCPartDAO.getInstance().DeletePO(wLoginUser, wPart, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_ActivePart(BMSEmployee wLoginUser, FPCPart wPart, int wActive) {
        // TODO Auto-generated method stub
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            FPCPartDAO.getInstance().FPC_ActivePart(wLoginUser, wPart, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<FPCPart> FPC_QueryPart(BMSEmployee wLoginUser, int wID, String wCode) {
        ServiceResult<FPCPart> wResult = new ServiceResult<FPCPart>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = FPCPartDAO.getInstance().FPC_QueryPart(wLoginUser, wID, wCode, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<FPCPart>> FPC_QueryPartList(BMSEmployee wLoginUser, String wName, int wActive,
                                                          Pagination wPagination) {
        // TODO Auto-generated method stub
        ServiceResult<List<FPCPart>> wResult = new ServiceResult<List<FPCPart>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = FPCPartDAO.getInstance().FPC_QueryPartList(wLoginUser, wName, wActive, wPagination,
                    wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_UpdatePartPoint(BMSEmployee wLoginUser, FPCPartPoint wPartPoint) {
        // TODO Auto-generated method stub
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            FPCPartPointDAO.getInstance().FPC_UpdatePartPoint(wLoginUser, wPartPoint, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_DeletePartPoint(BMSEmployee wLoginUser, FPCPartPoint wPartPoint) {
        // TODO Auto-generated method stub
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            FPCPartPointDAO.getInstance().DeletePO(wLoginUser, wPartPoint, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_ActivePartPoint(BMSEmployee wLoginUser, FPCPartPoint wPartPoint, int wActive) {
        // TODO Auto-generated method stub
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            FPCPartPointDAO.getInstance().FPC_ActivePartPoint(wLoginUser, wPartPoint, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<FPCPartPoint> FPC_QueryPartPoint(BMSEmployee wLoginUser, int wID, String wCode) {
        ServiceResult<FPCPartPoint> wResult = new ServiceResult<FPCPartPoint>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = FPCPartPointDAO.getInstance().FPC_QueryPartPoint(wLoginUser, wID, wCode, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<FPCPartPoint>> FPC_QueryPartPointList(BMSEmployee wLoginUser, String wName, int wActive,
                                                                    Pagination wPagination) {
        // TODO Auto-generated method stub
        ServiceResult<List<FPCPartPoint>> wResult = new ServiceResult<List<FPCPartPoint>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = FPCPartPointDAO.getInstance().FPC_QueryPartPointList(wLoginUser, wName, wActive,
                    wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_UpdateRoute(BMSEmployee wLoginUser, FPCRoute wRoute) {
        // TODO Auto-generated method stub
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            FPCRouteDAO.getInstance().FPC_UpdateRoute(wLoginUser, wRoute, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_DeleteRoute(BMSEmployee wLoginID, FPCRoute wRoute) {
        // TODO Auto-generated method stub
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            FPCRouteDAO.getInstance().FPC_DeleteRoute(wLoginID, wRoute, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_SetRouteToStandard(BMSEmployee wLoginUser, int wID) {
        // TODO Auto-generated method stub
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            if (wID <= 0) {
                return wResult;
            }

            FPCRoute wFPCRoute = FPCRouteDAO.getInstance().FPC_QueryRoute(wLoginUser, wID, wErrorCode);

            List<FPCRoutePart> wFPCRoutePartList = wFPCRoute.PartList;
            if (wFPCRoutePartList == null || wFPCRoutePartList.size() == 0) {
                wResult.FaultCode += "工序集不存在！";
                return wResult;
            }
            List<FPCRoutePartPoint> wFPCRoutePartPointList = new ArrayList<FPCRoutePartPoint>();
            boolean wIsOwnPart = false;
            for (FPCRoutePart fpcRoutePart : wFPCRoutePartList) {
                if (fpcRoutePart == null || fpcRoutePart.ID <= 0 || fpcRoutePart.Active != 1)
                    continue;
                if (fpcRoutePart.PartPointList == null || fpcRoutePart.PartPointList.size() == 0) {
                    wResult.FaultCode += "工序集" + fpcRoutePart.Name + "未设置工序！";
                    return wResult;
                }
                wFPCRoutePartPointList.addAll(fpcRoutePart.PartPointList);
                wIsOwnPart = true;
            }

            if (!wIsOwnPart) {
                wResult.FaultCode += "工序不存在！";
                return wResult;
            }

            if (wFPCRoutePartPointList.stream().noneMatch(p -> p.StationID != null && p.StationID.size() > 0)) {
                wResult.FaultCode += "BOP中未设置工序与工位对应关系！";
                return wResult;
            }

            Map<Integer, List<FPCRoutePartPoint>> wFPCRoutePartPointListMap = wFPCRoutePartPointList.stream()
                    .collect(Collectors.groupingBy(p -> p.RoutePartID));
            for (FPCRoutePart wFPCRoutePart : wFPCRoutePartList) {
                if (wFPCRoutePartPointListMap.containsKey(wFPCRoutePart.ID)
                        && wFPCRoutePartPointListMap.get(wFPCRoutePart.ID) != null
                        && wFPCRoutePartPointListMap.get(wFPCRoutePart.ID).size() > 0) {

                    continue;
                }
                wResult.FaultCode += StringUtils.Format("工序集：{0}中未设置工序；\n", wFPCRoutePart.Name);
            }

            if (StringUtils.isNotEmpty(wResult.FaultCode))
                return wResult;

            FPCRouteDAO.getInstance().FPC_SetRouteToStandard(wLoginUser, wID, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<FPCRoute> FPC_CopyRoute(BMSEmployee wLoginUser, FPCRoute wFPCRoute) {
        // TODO Auto-generated method stub
        ServiceResult<FPCRoute> wResult = new ServiceResult<FPCRoute>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);

            if (wFPCRoute == null || wFPCRoute.ID <= 0)
                return wResult;

            wFPCRoute.ID = 0;
            wFPCRoute.Code = "";
            FPCRouteDAO.getInstance().FPC_UpdateRoute(wLoginUser, wFPCRoute, wErrorCode);
            if (wFPCRoute.ID <= 0)
                return wResult;

            for (FPCRoutePart wFPCRoutePart : wFPCRoute.PartList) {
                if (wFPCRoutePart == null || wFPCRoutePart.ID <= 0)
                    continue;

                wFPCRoutePart.ID = 0;
                wFPCRoutePart.Code = "";
                wFPCRoutePart.RouteID = wFPCRoute.ID;
                wFPCRoutePart.RouteCode = wFPCRoute.Code;
                FPCRoutePartDAO.getInstance().FPC_UpdateRoutePart(wLoginUser, wFPCRoutePart, wErrorCode);
                if (wFPCRoutePart.ID <= 0)
                    continue;
                for (FPCRoutePartPoint wFPCRoutePartPoint : wFPCRoutePart.PartPointList) {
                    if (wFPCRoutePartPoint == null || wFPCRoutePartPoint.ID <= 0)
                        continue;

                    wFPCRoutePartPoint.ID = 0;
                    wFPCRoutePartPoint.Code = "";
                    wFPCRoutePartPoint.RouteID = wFPCRoute.ID;
                    wFPCRoutePartPoint.RouteCode = wFPCRoute.Code;
                    wFPCRoutePartPoint.RoutePartID = wFPCRoutePart.ID;
                    wFPCRoutePartPoint.RoutePartCode = wFPCRoutePart.Code;

                    FPCRoutePartPointDAO.getInstance().FPC_UpdateRoutePartPoint(wLoginUser, wFPCRoutePartPoint,
                            wErrorCode);

                    if (wFPCRoutePartPoint.ID <= 0)
                        continue;
                    for (FPCStepSOP wFPCStepSOP : wFPCRoutePartPoint.StepSOPList) {
                        if (wFPCStepSOP == null || wFPCStepSOP.ID <= 0)
                            continue;
                        wFPCStepSOP.ID = 0;
                        wFPCStepSOP.Code = "";
                        wFPCStepSOP.RouteID = wFPCRoute.ID;
                        wFPCStepSOP.RouteCode = wFPCRoute.Code;
                        wFPCStepSOP.RoutePartID = wFPCRoutePart.ID;
                        wFPCStepSOP.RoutePartCode = wFPCRoutePart.Code;
                        wFPCStepSOP.RoutePartPointID = wFPCRoutePartPoint.ID;
                        wFPCStepSOP.RoutePartPointCode = wFPCRoutePartPoint.Code;

                        FPCStepSOPDAO.getInstance().FPC_UpdateStepSOP(wLoginUser, wFPCStepSOP, wErrorCode);
                    }
                    for (FPCRouteStation wFPCRouteStation : wFPCRoutePartPoint.RouteStationList) {
                        if (wFPCRouteStation == null || wFPCRouteStation.ID <= 0)
                            continue;
                        wFPCRouteStation.RouteID = wFPCRoute.ID;
                        wFPCRouteStation.RouteCode = wFPCRoute.Code;
                        wFPCRouteStation.RoutePartID = wFPCRoutePart.ID;
                        wFPCRouteStation.RoutePartCode = wFPCRoutePart.Code;
                        wFPCRouteStation.RoutePartPointID = wFPCRoutePartPoint.ID;
                        wFPCRouteStation.RoutePartPointCode = wFPCRoutePartPoint.Code;
                        FPCRouteStationDAO.getInstance().FPC_UpdateRouteStation(wLoginUser, wFPCRouteStation,
                                wErrorCode);
                    }

                }
            }

            wResult.Result = wFPCRoute;
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_ActiveRoute(BMSEmployee wLoginUser, FPCRoute wRoute, int wActive) {
        // TODO Auto-generated method stub
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);

            FPCRouteDAO.getInstance().FPC_ActiveRoute(wLoginUser, wRoute, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<FPCRoute> FPC_QueryRoute(BMSEmployee wLoginUser, int wID, String wCode) {
        // TODO Auto-generated method stub
        ServiceResult<FPCRoute> wResult = new ServiceResult<FPCRoute>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = FPCRouteDAO.getInstance().FPC_QueryRoute(wLoginUser, wID, wCode, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<FPCRoute>> FPC_QueryRouteList(BMSEmployee wLoginUser, String wName, String wCodeLike,
                                                            int wFactoryID, int wLineID, int wCustomerID,
                                                            int wProductTypeID, int wProductID, String wProductNo,
                                                            int wType,
                                                            int wActive, int wIsStandard, int wHasItem,
                                                            Pagination wPagination) {
        // TODO Auto-generated method stub
        ServiceResult<List<FPCRoute>> wResult = new ServiceResult<List<FPCRoute>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = FPCRouteDAO.getInstance().FPC_QueryRouteList(wLoginUser, wName, wCodeLike, wFactoryID,
                    wLineID, wCustomerID, wProductTypeID, wProductID, wProductNo, wType, wActive, wIsStandard, wHasItem,
                    wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<FPCRoute> FPC_QueryRouteStandard(BMSEmployee wLoginUser, int wFactoryID, int wLineID,
                                                          int wCustomerID, int wProductID) {
        // TODO Auto-generated method stub
        ServiceResult<FPCRoute> wResult = new ServiceResult<FPCRoute>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = FPCRouteDAO.getInstance().FPC_QueryRouteStandard(wLoginUser, wFactoryID, wLineID,
                    wCustomerID, wProductID, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_UpdateRoutePart(BMSEmployee wLoginUser, FPCRoutePart wRoutePart) {
        // TODO Auto-generated method stub
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            FPCRoutePartDAO.getInstance().FPC_UpdateRoutePart(wLoginUser, wRoutePart, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_DeleteRoutePart(BMSEmployee wLoginUser, int wID) {
        // TODO Auto-generated method stub
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            FPCRoutePartDAO.getInstance().FPC_DeleteRoutePart(wLoginUser, wID, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<FPCRoutePart> FPC_QueryRoutePart(BMSEmployee wLoginUser, int wID, String wCode) {
        // TODO Auto-generated method stub
        ServiceResult<FPCRoutePart> wResult = new ServiceResult<FPCRoutePart>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = FPCRoutePartDAO.getInstance().FPC_QueryRoutePart(wLoginUser, wID, wCode, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<FPCRoutePart>> FPC_QueryRoutePartList(BMSEmployee wLoginUser, Integer wRouteID,
                                                                    int wActive, int wHasItem, Pagination wPagination) {
        // TODO Auto-generated method stub
        ServiceResult<List<FPCRoutePart>> wResult = new ServiceResult<List<FPCRoutePart>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = FPCRoutePartDAO.getInstance().FPC_QueryRoutePartList(wLoginUser, wRouteID, wActive,
                    wHasItem, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<FPCRoutePart>> FPC_QueryRoutePartList(BMSEmployee wLoginUser, List<Integer> wRouteID,
                                                                    String wName, String wPartCode, String wNameLike,
                                                                    int wActive, int wHasItem, Pagination wPagination) {
        // TODO Auto-generated method stub
        ServiceResult<List<FPCRoutePart>> wResult = new ServiceResult<List<FPCRoutePart>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = FPCRoutePartDAO.getInstance().FPC_QueryRoutePartList(wLoginUser, wRouteID, wName,
                    wPartCode, wNameLike, wActive, wHasItem, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_UpdateRoutePartPoint(BMSEmployee wLoginUser, FPCRoutePartPoint wRoutePartPoint) {
        // TODO Auto-generated method stub
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            FPCRoutePartPointDAO.getInstance().FPC_UpdateRoutePartPoint(wLoginUser, wRoutePartPoint, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_DeleteRoutePartPoint(BMSEmployee wLoginUser, int wID) {
        // TODO Auto-generated method stub
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            FPCRoutePartPointDAO.getInstance().FPC_DeleteRoutePartPoint(wLoginUser, wID, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<FPCRoutePartPoint> FPC_QueryRoutePartPoint(BMSEmployee wLoginUser, int wID, String wCode) {
        // TODO Auto-generated method stub
        ServiceResult<FPCRoutePartPoint> wResult = new ServiceResult<FPCRoutePartPoint>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = FPCRoutePartPointDAO.getInstance().FPC_QueryRoutePartPoint(wLoginUser, wID, wCode,
                    wErrorCode);

            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<FPCRoutePartPoint> FPC_QueryRoutePartPoint(BMSEmployee wLoginUser, int wRouteID,
                                                                    String wPartCode, String wRoutePartName,
                                                                    String wName, String wPartPointCode) {
        // TODO Auto-generated method stub
        ServiceResult<FPCRoutePartPoint> wResult = new ServiceResult<FPCRoutePartPoint>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = FPCRoutePartPointDAO.getInstance().FPC_QueryRoutePartPoint(wLoginUser, wRouteID, wPartCode,
                    wRoutePartName, wName, wPartPointCode, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<FPCRoutePartPoint>> FPC_QueryRoutePartPointList(BMSEmployee wLoginUser, int wRouteID,
                                                                              List<Integer> wRoutePartID,
                                                                              String wRoutePartName, String wPartCode
            , String wName, String wPartPointCode,
                                                                              String wNameLike, int wActive,
                                                                              int wHasItem, Pagination wPagination) {
        // TODO Auto-generated method stub
        ServiceResult<List<FPCRoutePartPoint>> wResult = new ServiceResult<List<FPCRoutePartPoint>>();
        try {
            wResult.Result = new ArrayList<FPCRoutePartPoint>();
            if (wRouteID <= 0)
                return wResult;

            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            wResult.Result = FPCRoutePartPointDAO.getInstance().FPC_QueryRoutePartPointList(wLoginUser, wRouteID,
                    wRoutePartID, wRoutePartName, wPartCode, wName, wPartPointCode, wNameLike, wActive, wHasItem,
                    wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<FPCStepSOP>> FPC_GetSOPList(BMSEmployee wLoginUser, int wRouteID, int wRoutePartID,
                                                          List<Integer> wRoutePartPointID, String wRoutePartName,
                                                          String wPartCode, String wRoutePartPointName,
                                                          String wPartPointCode, String wNameLike, int wActive,
                                                          Pagination wPagination) {
        // TODO Auto-generated method stub
        ServiceResult<List<FPCStepSOP>> wResult = new ServiceResult<List<FPCStepSOP>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = FPCStepSOPDAO.getInstance().FPC_QueryStepSOPList(wLoginUser, wRouteID, wRoutePartID,
                    wRoutePartPointID, wRoutePartName, wPartCode, wRoutePartPointName, wPartPointCode, wNameLike,
                    wActive, wPagination, wErrorCode);

            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<FPCStepSOP>> FPC_GetSOPList(BMSEmployee wLoginUser, int wRoutePartID,
                                                          String wRoutePartPointName, String wPartPointCode,
                                                          String wNameLike) {
        // TODO Auto-generated method stub
        ServiceResult<List<FPCStepSOP>> wResult = new ServiceResult<List<FPCStepSOP>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = FPCStepSOPDAO.getInstance().FPC_QueryStepSOPList(wLoginUser, wRoutePartID,
                    wRoutePartPointName, wPartPointCode, wNameLike, wErrorCode);

            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<FPCStepSOP>> FPC_GetSOPList(BMSEmployee wLoginUser, int wRouteID, String wRoutePartName,
                                                          String wPartCode, String wRoutePartPointName,
                                                          String wPartPointCode, String wNameLike) {
        // TODO Auto-generated method stub
        ServiceResult<List<FPCStepSOP>> wResult = new ServiceResult<List<FPCStepSOP>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = FPCStepSOPDAO.getInstance().FPC_QueryStepSOPList(wLoginUser, wRouteID, wRoutePartName,
                    wPartCode, wRoutePartPointName, wPartPointCode, wNameLike, wErrorCode);

            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_UpdateSOP(BMSEmployee wLoginUser, FPCStepSOP wFPCStepSOP) {
        // TODO Auto-generated method stub
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            FPCStepSOPDAO.getInstance().FPC_UpdateStepSOP(wLoginUser, wFPCStepSOP, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_ActiveSOP(BMSEmployee wLoginUser, FPCStepSOP wFPCStepSOP, int wActive) {
        // TODO Auto-generated method stub
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            FPCStepSOPDAO.getInstance().FPC_ActiveStepSOP(wLoginUser, wFPCStepSOP, wActive, wErrorCode);

            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_DeleteSOP(BMSEmployee wLoginUser, FPCStepSOP wFPCStepSOP) {
        // TODO Auto-generated method stub
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            FPCStepSOPDAO.getInstance().DeletePO(wLoginUser, wFPCStepSOP, wErrorCode);

            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<FPCRouteStation>> FPC_GetRouteStationList(BMSEmployee wLoginUser, int wStationID,
                                                                        String wCode, int wRouteID, int wRoutePartID,
                                                                        List<Integer> wRoutePartPointID,
                                                                        String wRoutePartName,
                                                                        String wPartCode, String wRoutePartPointName,
                                                                        String wPartPointCode, String wNameLike,
                                                                        int wActive,
                                                                        Pagination wPagination) {
        // TODO Auto-generated method stub
        ServiceResult<List<FPCRouteStation>> wResult = new ServiceResult<List<FPCRouteStation>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = FPCRouteStationDAO.getInstance().FPC_QueryRouteStationList(wLoginUser, wStationID, wCode,
                    wRouteID, wRoutePartID, wRoutePartPointID, wRoutePartName, wPartCode, wRoutePartPointName,
                    wPartPointCode, wNameLike, wActive, wPagination, wErrorCode);

            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<FPCRouteStation>> FPC_GetRouteStationList(BMSEmployee wLoginUser, int wRoutePartID,
                                                                        String wRoutePartPointName,
                                                                        String wPartPointCode, String wNameLike) {
        // TODO Auto-generated method stub
        ServiceResult<List<FPCRouteStation>> wResult = new ServiceResult<List<FPCRouteStation>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = FPCRouteStationDAO.getInstance().FPC_QueryRouteStationList(wLoginUser, wRoutePartID,
                    wRoutePartPointName, wPartPointCode, wNameLike, wErrorCode);

            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<FPCRouteStation>> FPC_GetRouteStationList(BMSEmployee wLoginUser, int wRouteID,
                                                                        String wRoutePartName, String wPartCode,
                                                                        String wRoutePartPointName,
                                                                        String wPartPointCode,
                                                                        String wNameLike) {
        // TODO Auto-generated method stub
        ServiceResult<List<FPCRouteStation>> wResult = new ServiceResult<List<FPCRouteStation>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = FPCRouteStationDAO.getInstance().FPC_QueryRouteStationList(wLoginUser, wRouteID,
                    wRoutePartName, wPartCode, wRoutePartPointName, wPartPointCode, wNameLike, wErrorCode);

            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_UpdateRouteStation(BMSEmployee wLoginUser, FPCRouteStation wFPCRouteStation) {
        // TODO Auto-generated method stub
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            FPCRouteStationDAO.getInstance().FPC_UpdateRouteStation(wLoginUser, wFPCRouteStation, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_ActiveRouteStation(BMSEmployee wLoginUser, FPCRouteStation wFPCRouteStation,
                                                         int wActive) {
        // TODO Auto-generated method stub
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            FPCRouteStationDAO.getInstance().FPC_ActiveRouteStation(wLoginUser, wFPCRouteStation, wActive, wErrorCode);

            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_DeleteRouteStation(BMSEmployee wLoginUser, FPCRouteStation wFPCRouteStation) {
        // TODO Auto-generated method stub
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            FPCRouteStationDAO.getInstance().DeletePO(wLoginUser, wFPCRouteStation, wErrorCode);

            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }


    @Override
    public ServiceResult<Integer> FPC_ActiveRoutePart(BMSEmployee wLoginUser, FPCRoutePart wRoutePart, int wActive) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            FPCRoutePartDAO.getInstance().FPC_ActiveRoutePart(wLoginUser, wRoutePart, wActive, wErrorCode);

            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_ActiveRoutePartPoint(BMSEmployee wLoginUser, FPCRoutePartPoint wRoutePartPoint,
                                                           int wActive) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            FPCRoutePartPointDAO.getInstance().FPC_ActiveRoutePartPoint(wLoginUser, wRoutePartPoint, wActive,
                    wErrorCode);

            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<FPCStepSOP>> FPC_GetSOPList(BMSEmployee wLoginUser, int wRoutePartPointID,
                                                          String wNameLike) {
        ServiceResult<List<FPCStepSOP>> wResult = new ServiceResult<List<FPCStepSOP>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = FPCStepSOPDAO.getInstance().FPC_QueryStepSOPList(wLoginUser, wRoutePartPointID, wNameLike,
                    wErrorCode);

            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<FPCRouteStation>> FPC_GetRouteStationList(BMSEmployee wLoginUser, int wRoutePartPointID,
                                                                        String wNameLike) {
        ServiceResult<List<FPCRouteStation>> wResult = new ServiceResult<List<FPCRouteStation>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = FPCRouteStationDAO.getInstance().FPC_QueryRouteStationList(wLoginUser, wRoutePartPointID,
                    wNameLike, wErrorCode);

            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    @Override
    public ServiceResult<FPCRouteStation> FPC_QueryRouteStation(BMSEmployee wLoginUser, int wID) {
        ServiceResult<FPCRouteStation> wResult = new ServiceResult<FPCRouteStation>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = FPCRouteStationDAO.getInstance().FPC_QueryRouteStation(wLoginUser, wID, wErrorCode);

            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
            wResult.FaultCode += e.getMessage();
        }
        return wResult;
    }

    //endregion

    //region 新版工艺bop

    @Override
    public ServiceResult<Integer> FPC_RouteSetCurrent(BMSEmployee wBMSEmployee, FPCRoute wRoute, int wIsStandard) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            PoService<FPCRoute> mFPCRouteService = ORMUtils.GetPoService(FPCRoute.class);
            PoService<FPCRouteParent> mFPCRouteParentService = ORMUtils.GetPoService(FPCRouteParent.class);

            if (wRoute.BOPParentID <= 0) {
                wResult.FaultCode += RetCode.SERVER_RST_ERROR_OUT;
                return wResult;
            }

            //①若是取消当前，则直接修改属性即可
            if (wIsStandard != 1) {
                wRoute.IsStandard = wIsStandard;
                mFPCRouteService.UpdatePo(wBMSEmployee, wRoute, wErrorCode);

                //维护父表当前版本
                Map<String, Object> wParams = new HashMap<String, Object>();
                wParams.put("ID", wRoute.BOPParentID);

                FPCRouteParent wFPCRouteParent = mFPCRouteParentService.SelectPO(wBMSEmployee, wParams, wErrorCode);
                if (wFPCRouteParent.ID > 0) {
                    wFPCRouteParent.RouteID = 0;
                    wFPCRouteParent.IsRoutID = 0;
                    mFPCRouteParentService.UpdatePo(wBMSEmployee, wFPCRouteParent, wErrorCode);
                }
            } else {
                //设置为当前，判断该工艺路线是否已审批，若没有，则报错
                if (wRoute.Status != FPCRouteStatus.AUDITED.getValue()) {
                    wResult.FaultCode += StringUtils.Format("工艺路线【{0}】未审批!", wRoute.Version);
                    return wResult;
                }
                //②若是设置为当前，则根据ParentID查询集合
                Map<String, Object> wParamsMap = new HashMap<String, Object>();
                wParamsMap.put("BOPParentID", wRoute.BOPParentID);
                List<FPCRoute> wFPCRouteList = mFPCRouteService.SelectPOList(wBMSEmployee, wParamsMap,
                        Pagination.getMaxSize(), wErrorCode);
                //③取消其他版本bop
                wFPCRouteList = wFPCRouteList.stream().filter(p -> p.ID != wRoute.ID).collect(Collectors.toList());
                for (FPCRoute fpcRoute : wFPCRouteList) {
                    fpcRoute.IsStandard = 0;
                    mFPCRouteService.UpdatePo(wBMSEmployee, fpcRoute, wErrorCode);
                }
                //④将当前版本bop设置为当前
                wRoute.IsStandard = wIsStandard;
                mFPCRouteService.UpdatePo(wBMSEmployee, wRoute, wErrorCode);

                //维护父表当前版本
                Map<String, Object> wParams = new HashMap<String, Object>();
                wParams.put("ID", wRoute.BOPParentID);

                FPCRouteParent wFPCRouteParent = mFPCRouteParentService.SelectPO(wBMSEmployee, wParams, wErrorCode);
                if (wFPCRouteParent.ID > 0) {
                    wFPCRouteParent.RouteID = wRoute.ID;
                    wFPCRouteParent.IsRoutID = 1;
                    mFPCRouteParentService.UpdatePo(wBMSEmployee, wFPCRouteParent, wErrorCode);
                }
            }

            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_ImportRoute(BMSEmployee wLoginUser, ExcelData wExcelData) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            if (wExcelData == null || wExcelData.sheetData == null || wExcelData.sheetData.size() <= 6) {
                wResult.FaultCode += "导入失败：Excel格式错误!!!";
                return wResult;
            }

            //①导入路线
            ServiceResult<List<FPCRoute>> wFPCRouteListSR = this.FPC_ImportRoute_Line(wLoginUser,
                    wExcelData.sheetData.get(0));
            if (StringUtils.isNotEmpty(wFPCRouteListSR.FaultCode)) {
                wResult.FaultCode = wFPCRouteListSR.FaultCode;
                return wResult;
            }
            //②导入工艺
            ServiceResult<List<FPCRoutePart>> wFPCRoutePartListSR =
                    this.FPC_ImportRoute_RoutePart(wLoginUser, wExcelData.sheetData.get(1), wFPCRouteListSR.Result);
            if (StringUtils.isNotEmpty(wFPCRoutePartListSR.FaultCode)) {
                wResult.FaultCode = wFPCRoutePartListSR.FaultCode;
                return wResult;
            }
            //③导入工序
            ServiceResult<List<FPCRoutePartPoint>> wFPCRoutePartPointListSR =
                    this.FPC_ImportRoute_RoutePartPoint(wLoginUser, wExcelData.sheetData.get(2), wFPCRouteListSR.Result,
                            wFPCRoutePartListSR.Result);
            if (StringUtils.isNotEmpty(wFPCRoutePartPointListSR.FaultCode)) {
                wResult.FaultCode = wFPCRoutePartPointListSR.FaultCode;
                return wResult;
            }
            //④导入工步
            ServiceResult<Integer> wStepSR = this.FPC_ImportRoute_RouteStep(wLoginUser, wExcelData.sheetData.get(3),
                    wFPCRoutePartPointListSR.Result, wFPCRouteListSR.Result);
            if (StringUtils.isNotEmpty(wStepSR.FaultCode)) {
                wResult.FaultCode = wStepSR.FaultCode;
                return wResult;
            }
            //⑤导入工序物料
            ServiceResult<Integer> wPartPointMaterialSR =
                    this.FPC_ImportRoute_PartPointMaterial(wLoginUser, wExcelData.sheetData.get(4),
                            wFPCRoutePartPointListSR.Result);
            if (StringUtils.isNotEmpty(wPartPointMaterialSR.FaultCode)) {
                wResult.FaultCode = wPartPointMaterialSR.FaultCode;
                return wResult;
            }
            //⑥导入工序量器具
            ServiceResult<Integer> wPartPointLQJSR = this.FPC_ImportRoute_PartPointLQJ(wLoginUser,
                    wExcelData.sheetData.get(5),
                    wFPCRoutePartPointListSR.Result);
            if (StringUtils.isNotEmpty(wPartPointLQJSR.FaultCode)) {
                wResult.FaultCode = wPartPointLQJSR.FaultCode;
                return wResult;
            }
            //⑦导入工序工装
            ServiceResult<Integer> wPartPointFrockSR = this.FPC_ImportRoute_PartPointFrock(wLoginUser,
                    wExcelData.sheetData.get(6),
                    wFPCRoutePartPointListSR.Result);
            if (StringUtils.isNotEmpty(wPartPointFrockSR.FaultCode)) {
                wResult.FaultCode = wPartPointFrockSR.FaultCode;
                return wResult;
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("FPC_ImportRoute", e);
        }
        return wResult;
    }

    /**
     * 导入工序工装
     */
    private ServiceResult<Integer> FPC_ImportRoute_PartPointFrock(BMSEmployee wLoginUser,
                                                                  ExcelSheetData wExcelSheetData,
                                                                  List<FPCRoutePartPoint> wFPCRoutePartPointList) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            if (wExcelSheetData.lineData == null || wExcelSheetData.lineData.size() <= 1) {
                return wResult;
            }

            Map<String, Integer> wNameIDPartPointMap =
                    wFPCRoutePartPointList.stream().collect(Collectors.toMap(FPCRoutePartPoint::getName
                            , FPCRoutePartPoint::getID));
            Map<String, FPCRoutePartPoint> wNamePartPointMap =
                    wFPCRoutePartPointList.stream().collect(Collectors.toMap(FPCRoutePartPoint::getName
                            , p -> p));

            //量器具
            Map<String, Object> wParams = new HashMap<String, Object>();
            List<AMSFrockTool> wAMSFrockToolList = mAMSFrockToolService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            Map<String, Integer> wCodeIDFrockMap =
                    wAMSFrockToolList.stream().collect(Collectors.toMap(AMSFrockTool::getCode
                            , AMSFrockTool::getID));

            List<FPCRouteFrockTool> wFPCRouteFrockToolList = new ArrayList<>();
            FPCRouteFrockTool wFPCRouteFrockTool;
            for (int i = 0; i < wExcelSheetData.lineData.size(); i++) {
                if (i == 0) {
                    continue;
                }

                ExcelLineData wExcelLineData = wExcelSheetData.lineData.get(i);
                int wIndex = 0;

                //工序名称
                String wCol1 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol1)) {
                    continue;
                }
                if (!wNameIDPartPointMap.containsKey(wCol1)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet7】第【{0}】行数据有误，工序名称【{1}】不存在!!!", i + 1, wCol1);
                    return wResult;
                }
                //工装名称
                String wCol2 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol2)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet7】第【{0}】行数据有误，工装名称不能为空!!!", i + 1);
                    return wResult;
                }
                //工装编码
                String wCol3 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol3)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet7】第【{0}】行数据有误，工装编码不能为空!!!", i + 1);
                    return wResult;
                }
                if (!wCodeIDFrockMap.containsKey(wCol3)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet7】第【{0}】行数据有误，工装编码【{1}】不存在!!!", i + 1, wCol3);
                    return wResult;
                }
                //数量
                String wCol4 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol4)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet6】第【{0}】行数据有误，数量不能为空!!!", i + 1);
                    return wResult;
                }
                //描述信息
                String wCol5 = wExcelLineData.colData.get(wIndex++);

                wFPCRouteFrockTool = new FPCRouteFrockTool();
                wFPCRouteFrockTool.RouteID = wNamePartPointMap.get(wCol1).RouteID;
                wFPCRouteFrockTool.RoutePartID = wNamePartPointMap.get(wCol1).RoutePartID;
                wFPCRouteFrockTool.RoutePartPointID = wNamePartPointMap.get(wCol1).ID;
                wFPCRouteFrockTool.FrockToolID = wCodeIDFrockMap.get(wCol3);
                wFPCRouteFrockTool.Number = StringUtils.parseDouble(wCol4);
                wFPCRouteFrockTool.Description = wCol5;
                wFPCRouteFrockTool.setUserInfo(wLoginUser);
                wFPCRouteFrockToolList.add(wFPCRouteFrockTool);
            }

            if (wFPCRouteFrockToolList.size() > 0) {
                mFPCRouteFrockToolService.UpdatePoList(wLoginUser, wFPCRouteFrockToolList, wErrorCode);
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("FPC_ImportRoute_PartPointFrock", e);
        }
        return wResult;
    }

    /**
     * 导入工序量器具
     */
    private ServiceResult<Integer> FPC_ImportRoute_PartPointLQJ(BMSEmployee wLoginUser, ExcelSheetData wExcelSheetData,
                                                                List<FPCRoutePartPoint> wFPCRoutePartPointList) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            if (wExcelSheetData.lineData == null || wExcelSheetData.lineData.size() <= 1) {
                return wResult;
            }

            Map<String, Integer> wNameIDPartPointMap =
                    wFPCRoutePartPointList.stream().collect(Collectors.toMap(FPCRoutePartPoint::getName
                            , FPCRoutePartPoint::getID));
            Map<String, FPCRoutePartPoint> wNamePartPointMap =
                    wFPCRoutePartPointList.stream().collect(Collectors.toMap(FPCRoutePartPoint::getName
                            , p -> p));

            //量器具
            Map<String, Object> wParams = new HashMap<String, Object>();
            List<AMSMeasureTool> wAMSMeasureToolList = mAMSMeasureToolService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            Map<String, Integer> wCodeIDMeasureMap =
                    wAMSMeasureToolList.stream().collect(Collectors.toMap(AMSMeasureTool::getCode
                            , AMSMeasureTool::getID));

            List<FPCRouteMeasureTool> wFPCRouteMeasureToolList = new ArrayList<>();
            FPCRouteMeasureTool wFPCRouteMeasureTool;
            for (int i = 0; i < wExcelSheetData.lineData.size(); i++) {
                if (i == 0) {
                    continue;
                }

                ExcelLineData wExcelLineData = wExcelSheetData.lineData.get(i);
                int wIndex = 0;

                //工序名称
                String wCol1 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol1)) {
                    continue;
                }
                if (!wNameIDPartPointMap.containsKey(wCol1)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet6】第【{0}】行数据有误，工序名称【{1}】不存在!!!", i + 1, wCol1);
                    return wResult;
                }
                //量器具名称
                String wCol2 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol2)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet6】第【{0}】行数据有误，量器具名称不能为空!!!", i + 1);
                    return wResult;
                }
                //量器具编码
                String wCol3 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol3)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet6】第【{0}】行数据有误，量器具编码不能为空!!!", i + 1);
                    return wResult;
                }
                if (!wCodeIDMeasureMap.containsKey(wCol3)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet6】第【{0}】行数据有误，量器具编码【{1}】不存在!!!", i + 1, wCol3);
                    return wResult;
                }
                //数量
                String wCol4 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol4)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet6】第【{0}】行数据有误，数量不能为空!!!", i + 1);
                    return wResult;
                }
                //描述信息
                String wCol5 = wExcelLineData.colData.get(wIndex++);

                wFPCRouteMeasureTool = new FPCRouteMeasureTool();
                wFPCRouteMeasureTool.RouteID = wNamePartPointMap.get(wCol1).RouteID;
                wFPCRouteMeasureTool.RoutePartID = wNamePartPointMap.get(wCol1).RoutePartID;
                wFPCRouteMeasureTool.RoutePartPointID = wNamePartPointMap.get(wCol1).ID;
                wFPCRouteMeasureTool.MeasureToolID = wCodeIDMeasureMap.get(wCol3);
                wFPCRouteMeasureTool.Number = StringUtils.parseDouble(wCol4);
                wFPCRouteMeasureTool.Description = wCol5;
                wFPCRouteMeasureTool.setUserInfo(wLoginUser);
                wFPCRouteMeasureToolList.add(wFPCRouteMeasureTool);
            }

            if (wFPCRouteMeasureToolList.size() > 0) {
                mFPCRouteMeasureToolService.UpdatePoList(wLoginUser, wFPCRouteMeasureToolList, wErrorCode);
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("FPC_ImportRoute_PartPointLQJ", e);
        }
        return wResult;
    }

    /**
     * 导入工序物料
     */
    private ServiceResult<Integer> FPC_ImportRoute_PartPointMaterial(BMSEmployee wLoginUser,
                                                                     ExcelSheetData wExcelSheetData,
                                                                     List<FPCRoutePartPoint> wFPCRoutePartPointList) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            if (wExcelSheetData.lineData == null || wExcelSheetData.lineData.size() <= 1) {
                wResult.FaultCode += "导入失败：【Sheet5】无内容!!!";
                return wResult;
            }

            Map<String, Integer> wNameIDPartPointMap =
                    wFPCRoutePartPointList.stream().collect(Collectors.toMap(FPCRoutePartPoint::getName
                            , FPCRoutePartPoint::getID));
            Map<String, FPCRoutePartPoint> wNamePartPointMap =
                    wFPCRoutePartPointList.stream().collect(Collectors.toMap(FPCRoutePartPoint::getName
                            , p -> p));

            //物料主数据
            Map<String, Object> wParams = new HashMap<String, Object>();
            List<MSSMaterial> wMSSMaterialList = mMSSMaterialService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wMSSMaterialList == null || wMSSMaterialList.size() <= 0) {
                wResult.FaultCode += StringUtils.Format("导入失败：未获取到物料主数据信息!!!");
                return wResult;
            }
            wMSSMaterialList = new ArrayList<MSSMaterial>(wMSSMaterialList.stream()
                    .collect(Collectors.toMap(MSSMaterial::getCode, account -> account, (k1, k2) -> k2)).values());
            Map<String, Integer> wCodeIDMaterialMap =
                    wMSSMaterialList.stream().collect(Collectors.toMap(MSSMaterial::getCode
                            , MSSMaterial::getID));

            List<MSSBOMItem> wMSSBOMItemList = new ArrayList<>();
            MSSBOMItem wMSSBOMItem;
            for (int i = 0; i < wExcelSheetData.lineData.size(); i++) {
                if (i == 0) {
                    continue;
                }

                ExcelLineData wExcelLineData = wExcelSheetData.lineData.get(i);
                int wIndex = 0;

                //工序名称
                String wCol1 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol1)) {
                    continue;
                }
                if (!wNameIDPartPointMap.containsKey(wCol1)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet5】第【{0}】行数据有误，工序名称【{1}】不存在!!!", i + 1, wCol1);
                    return wResult;
                }
                //物料名称
                String wCol2 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol2)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet5】第【{0}】行数据有误，物料名称不能为空!!!", i + 1);
                    return wResult;
                }
                //物料编码
                String wCol3 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol3)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet5】第【{0}】行数据有误，物料编码不能为空!!!", i + 1);
                    return wResult;
                }
                if (!wCodeIDMaterialMap.containsKey(wCol3)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet5】第【{0}】行数据有误，物料编码【{1}】不存在!!!", i + 1, wCol3);
                    return wResult;
                }
                //物料数量
                String wCol4 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol4)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet5】第【{0}】行数据有误，物料数量不能为空!!!", i + 1);
                    return wResult;
                }
                //描述信息
                String wCol5 = wExcelLineData.colData.get(wIndex++);

                wMSSBOMItem = new MSSBOMItem();
                wMSSBOMItem.RouteID = wNamePartPointMap.get(wCol1).RouteID;
                wMSSBOMItem.RoutePartID = wNamePartPointMap.get(wCol1).RoutePartID;
                wMSSBOMItem.RoutePartPointID = wNamePartPointMap.get(wCol1).ID;
                wMSSBOMItem.MaterialID = wCodeIDMaterialMap.get(wCol3);
                wMSSBOMItem.MaterialNumber = StringUtils.parseDouble(wCol4);
                wMSSBOMItem.Description = wCol5;
                wMSSBOMItem.setUserInfo(wLoginUser);
                wMSSBOMItemList.add(wMSSBOMItem);
            }

            if (wMSSBOMItemList.size() > 0) {
                mMSSBOMItemService.UpdatePoList(wLoginUser, wMSSBOMItemList, wErrorCode);
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("FPC_ImportRoute_PartPointMaterial", e);
        }
        return wResult;
    }

    /**
     * 导入工步
     */
    private ServiceResult<Integer> FPC_ImportRoute_RouteStep(BMSEmployee wLoginUser, ExcelSheetData wExcelSheetData,
                                                             List<FPCRoutePartPoint> wFPCRoutePartPointList,
                                                             List<FPCRoute> wFPCRouteList) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            if (wExcelSheetData.lineData == null || wExcelSheetData.lineData.size() <= 1) {
                wResult.FaultCode += "导入失败：【Sheet4】无内容!!!";
                return wResult;
            }

            Map<String, Integer> wNameIDPartPointMap =
                    wFPCRoutePartPointList.stream().collect(Collectors.toMap(FPCRoutePartPoint::getName
                            , FPCRoutePartPoint::getID));
            Map<String, FPCRoutePartPoint> wNamePartPointMap =
                    wFPCRoutePartPointList.stream().collect(Collectors.toMap(FPCRoutePartPoint::getName
                            , p -> p));

            List<FPCRouteStep> wFPCRouteStepList = new ArrayList<>();
            FPCRouteStep wFPCRouteStep;
            for (int i = 0; i < wExcelSheetData.lineData.size(); i++) {
                if (i == 0) {
                    continue;
                }

                ExcelLineData wExcelLineData = wExcelSheetData.lineData.get(i);
                int wIndex = 0;

                //工序名称
                String wCol1 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol1)) {
                    continue;
                }
                if (!wNameIDPartPointMap.containsKey(wCol1)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet4】第【{0}】行数据有误，工序名称【{1}】不存在!!!", i + 1, wCol1);
                    return wResult;
                }
                //作业顺序
                String wCol2 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol2)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet4】第【{0}】行数据有误，作业顺序不能为空!!!", i + 1);
                    return wResult;
                }
                //作业工时
                String wCol3 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol3)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet4】第【{0}】行数据有误，作业工时不能为空!!!", i + 1);
                    return wResult;
                }
                //作业内容
                String wCol4 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol4)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet4】第【{0}】行数据有误，作业内容不能为空!!!", i + 1);
                    return wResult;
                }
                //作业要求
                String wCol5 = wExcelLineData.colData.get(wIndex++);
//                if (StringUtils.isEmpty(wCol5)) {
//                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet4】第【{0}】行数据有误，作业要求不能为空!!!", i + 1);
//                    return wResult;
//                }
                //检验标准
                String wCol6 = wExcelLineData.colData.get(wIndex++);
//                if (StringUtils.isEmpty(wCol6)) {
//                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet4】第【{0}】行数据有误，检验标准不能为空!!!", i + 1);
//                    return wResult;
//                }
                //作业人数
                String wCol7 = wExcelLineData.colData.get(wIndex++);
//                if (StringUtils.isEmpty(wCol7)) {
//                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet4】第【{0}】行数据有误，作业人数不能为空!!!", i + 1);
//                    return wResult;
//                }
                //是否必填
                String wCol8 = wExcelLineData.colData.get(wIndex++);
                //是否首检
                String wCol9 = wExcelLineData.colData.get(wIndex++);
                //是否自检
                String wCol10 = wExcelLineData.colData.get(wIndex++);
                //是否互检
                String wCol11 = wExcelLineData.colData.get(wIndex++);
                //是否专检
                String wCol12 = wExcelLineData.colData.get(wIndex++);

                wFPCRouteStep = new FPCRouteStep();
                wFPCRouteStep.RouteID = wNamePartPointMap.get(wCol1).RouteID;
                wFPCRouteStep.RoutePartID = wNamePartPointMap.get(wCol1).RoutePartID;
                wFPCRouteStep.RoutePartPointID = wNamePartPointMap.get(wCol1).ID;
                wFPCRouteStep.StepOrder = StringUtils.parseInt(wCol2);
                wFPCRouteStep.WorkTime = StringUtils.parseDouble(wCol3);
                wFPCRouteStep.WorkContent = wCol4;
                wFPCRouteStep.WorkRequirements = wCol5;
                wFPCRouteStep.CheckStandard = wCol6;
                wFPCRouteStep.PersonNumber = StringUtils.parseInt(wCol7);
                wFPCRouteStep.IsRequired = wCol8.equals("是") ? 1 : 0;
                wFPCRouteStep.IsFirstCheck = wCol9.equals("是") ? 1 : 0;
                wFPCRouteStep.IsSelfCheck = wCol10.equals("是") ? 1 : 0;
                wFPCRouteStep.IsMutualCheck = wCol11.equals("是") ? 1 : 0;
                wFPCRouteStep.IsSpecialCheck = wCol12.equals("是") ? 1 : 0;
                wFPCRouteStep.setUserInfo(wLoginUser);
                wFPCRouteStepList.add(wFPCRouteStep);
            }

            if (wFPCRouteStepList.size() > 0) {
                mFPCRouteStepService.UpdatePoList(wLoginUser, wFPCRouteStepList, wErrorCode);
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("FPC_ImportRoute_RouteStep", e);
        }
        return wResult;
    }

    /**
     * 导入工序
     */
    private ServiceResult<List<FPCRoutePartPoint>> FPC_ImportRoute_RoutePartPoint(BMSEmployee wLoginUser,
                                                                                  ExcelSheetData wExcelSheetData,
                                                                                  List<FPCRoute> wFPCRouteList,
                                                                                  List<FPCRoutePart> wFPCRoutePartList) {
        ServiceResult<List<FPCRoutePartPoint>> wResult = new ServiceResult<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            if (wExcelSheetData.lineData == null || wExcelSheetData.lineData.size() <= 1) {
                wResult.FaultCode += "导入失败：【Sheet3】无内容!!!";
                return wResult;
            }

            //①工位列表
            Map<String, Object> wParams = new HashMap<String, Object>();
            List<FMCStation> wFMCStationList = mFMCStationService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wFMCStationList == null || wFMCStationList.size() <= 0) {
                wResult.FaultCode += "导入失败：未获取到工位信息!!!";
                return wResult;
            }
            Map<String, Integer> wNameIDStationMap =
                    wFMCStationList.stream().collect(Collectors.toMap(FMCStation::getName
                            , FMCStation::getID));

            //②工艺路线
            if (wFPCRouteList == null || wFPCRouteList.size() <= 0) {
                wResult.FaultCode += "导入失败：未获取到工艺路线信息!!!";
                return wResult;
            }

            Map<String, Integer> wNameIDRouteMap =
                    wFPCRouteList.stream().collect(Collectors.toMap(FPCRoute::getName
                            , FPCRoute::getID));

            //②工艺集
            if (wFPCRoutePartList == null || wFPCRoutePartList.size() <= 0) {
                wResult.FaultCode += "导入失败：未获取到工艺集信息!!!";
                return wResult;
            }

            Map<String, Integer> wNameIDRoutePartMap =
                    wFPCRoutePartList.stream().collect(Collectors.toMap(FPCRoutePart::getName
                            , FPCRoutePart::getID));

            List<FPCRoutePartPoint> wFPCRoutePartPointList = new ArrayList<>();
            FPCRoutePartPoint wFPCRoutePartPoint;
            for (int i = 0; i < wExcelSheetData.lineData.size(); i++) {
                if (i == 0) {
                    continue;
                }

                ExcelLineData wExcelLineData = wExcelSheetData.lineData.get(i);
                int wIndex = 0;

                //BOP编号
                String wCol1 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol1)) {
                    continue;
                }
                //工艺名称
                String wCol2 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol2)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet3】第【{0}】行数据有误，工艺名称不能为空!!!", i + 1);
                    return wResult;
                }
                if (!wNameIDRoutePartMap.containsKey(wCol2)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet3】第【{0}】行数据有误，工艺名称【{1}】不存在!!!", i + 1, wCol2);
                    return wResult;
                }
                //工序名称
                String wCol3 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol3)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet3】第【{0}】行数据有误，工序名称不能为空!!!", i + 1);
                    return wResult;
                }
                //作业工位
                String wCol4 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol4)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet3】第【{0}】行数据有误，作业工位不能为空!!!", i + 1);
                    return wResult;
                }
                List<Integer> wStationIDList = new ArrayList<>();
                if (wCol4.contains(",")) {
                    String[] wSplitList = wCol4.split(",");
                    for (String wSplit : wSplitList) {
                        if (!wNameIDStationMap.containsKey(wSplit)) {
                            wResult.FaultCode += StringUtils.Format("导入失败：【Sheet3】第【{0}】行数据有误，工位【{1}】不存在!!!", i + 1,
                                    wSplit);
                            return wResult;
                        }
                        wStationIDList.add(wNameIDStationMap.get(wSplit));
                    }
                } else if (wCol4.contains("，")) {
                    String[] wSplitList = wCol4.split("，");
                    for (String wSplit : wSplitList) {
                        if (!wNameIDStationMap.containsKey(wSplit)) {
                            wResult.FaultCode += StringUtils.Format("导入失败：【Sheet3】第【{0}】行数据有误，工位【{1}】不存在!!!", i + 1,
                                    wSplit);
                            return wResult;
                        }
                        wStationIDList.add(wNameIDStationMap.get(wSplit));
                    }
                } else {
                    if (!wNameIDStationMap.containsKey(wCol4)) {
                        wResult.FaultCode += StringUtils.Format("导入失败：【Sheet3】第【{0}】行数据有误，工位【{1}】不存在!!!", i + 1,
                                wCol4);
                        return wResult;
                    }
                    wStationIDList.add(wNameIDStationMap.get(wCol4));
                }
                //顺序
                String wCol5 = wExcelLineData.colData.get(wIndex++);
                //前工序
                String wCol6 = wExcelLineData.colData.get(wIndex++);
                //后工序
                String wCol7 = wExcelLineData.colData.get(wIndex++);
                //互检模式
                String wCol8 = wExcelLineData.colData.get(wIndex++);
                int wMutualType = FPCMutualModel.getEnumType(wCol8).getValue();
                //报工模式
                String wCol9 = wExcelLineData.colData.get(wIndex++);
                int wTaskReportMode = FPCTaskReportMode.getEnumType(wCol9).getValue();
                //自动报工数量
                String wCol10 = wExcelLineData.colData.get(wIndex++);
                //强制专检
                String wCol11 = wExcelLineData.colData.get(wIndex++);
                //报工交接
                String wCol12 = wExcelLineData.colData.get(wIndex++);
                //描述信息
                String wCol13 = wExcelLineData.colData.get(wIndex++);
                //工件类型
                String wCol14 = wExcelLineData.colData.get(wIndex++);
                int wComponentType = PDMComponentTypes.getEnumType(wCol14).getValue();

                wFPCRoutePartPoint = new FPCRoutePartPoint();
                wFPCRoutePartPoint.RouteID = wNameIDRouteMap.get(wCol1);
                wFPCRoutePartPoint.RoutePartID = wNameIDRoutePartMap.get(wCol2);
                wFPCRoutePartPoint.Name = wCol3;
                wFPCRoutePartPoint.StationID = wStationIDList;
                wFPCRoutePartPoint.OrderID = StringUtils.parseInt(wCol5);
                wFPCRoutePartPoint.PrevPartPointName = wCol6;
                wFPCRoutePartPoint.NextPartPointName = wCol7;
                wFPCRoutePartPoint.MutualModel = wMutualType;
                wFPCRoutePartPoint.ReportMode = wTaskReportMode;
                wFPCRoutePartPoint.ReportFQTY = StringUtils.parseInt(wCol10);
                wFPCRoutePartPoint.IsSpecialCheck = wCol11.equals("是") ? 1 : 0;
                wFPCRoutePartPoint.HandoverSemiProduct = wCol12.equals("是") ? 1 : 0;
                wFPCRoutePartPoint.Description = wCol13;
                wFPCRoutePartPoint.ComponentType = wComponentType;
                wFPCRoutePartPointList.add(wFPCRoutePartPoint);
            }

            if (wFPCRoutePartPointList.size() > 0) {
                mFPCRoutePartPointService.UpdatePoList(wLoginUser, wFPCRoutePartPointList, wErrorCode);
                if (wFPCRoutePartPointList.stream().anyMatch(p -> p.ID <= 0)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet3】保存工序失败!!!");
                    return wResult;
                }
                Map<String, Integer> wNameIDRoutePartPointMap =
                        wFPCRoutePartPointList.stream().collect(Collectors.toMap(FPCRoutePartPoint::getName
                                , FPCRoutePartPoint::getID));
                //更新前后工序
                for (FPCRoutePartPoint wFPCRoutePartPointItem : wFPCRoutePartPointList) {
                    //前工艺
                    if (StringUtils.isNotEmpty(wFPCRoutePartPointItem.PrevPartPointName)
                            && wNameIDRoutePartPointMap.containsKey(wFPCRoutePartPointItem.PrevPartPointName)) {
                        wFPCRoutePartPointItem.PrevPartPointID =
                                wNameIDRoutePartPointMap.get(wFPCRoutePartPointItem.PrevPartPointName);
                    }
                    //后工艺
                    if (StringUtils.isNotEmpty(wFPCRoutePartPointItem.NextPartPointName)) {
                        List<Integer> wIDList = new ArrayList<>();
                        if (wFPCRoutePartPointItem.NextPartPointName.contains(",")) {
                            String[] wSplitList = wFPCRoutePartPointItem.NextPartPointName.split(",");
                            for (String wSplit : wSplitList) {
                                if (wNameIDRoutePartPointMap.containsKey(wSplit)) {
                                    wIDList.add(wNameIDRoutePartPointMap.get(wSplit));
                                }
                            }
                        } else if (wFPCRoutePartPointItem.NextPartPointName.contains("，")) {
                            String[] wSplitList = wFPCRoutePartPointItem.NextPartPointName.split("，");
                            for (String wSplit : wSplitList) {
                                if (wNameIDRoutePartPointMap.containsKey(wSplit)) {
                                    wIDList.add(wNameIDRoutePartPointMap.get(wSplit));
                                }
                            }
                        } else {
                            if (wNameIDRoutePartPointMap.containsKey(wFPCRoutePartPointItem.NextPartPointName)) {
                                wIDList.add(wNameIDRoutePartPointMap.get(wFPCRoutePartPointItem.NextPartPointName));
                            }
                        }
                        wFPCRoutePartPointItem.NextPartPointID = wIDList;
                    }
                }
                mFPCRoutePartPointService.UpdatePoList(wLoginUser, wFPCRoutePartPointList, wErrorCode);
            }

            wResult.Result = wFPCRoutePartPointList;

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("FPC_ImportRoute_RoutePartPoint", e);
        }
        return wResult;
    }

    /**
     * 导入工艺
     */
    private ServiceResult<List<FPCRoutePart>> FPC_ImportRoute_RoutePart(BMSEmployee wLoginUser,
                                                                        ExcelSheetData wExcelSheetData,
                                                                        List<FPCRoute> wFPCRouteList) {
        ServiceResult<List<FPCRoutePart>> wResult = new ServiceResult<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            if (wExcelSheetData.lineData == null || wExcelSheetData.lineData.size() <= 1) {
                wResult.FaultCode += "导入失败：【Sheet2】无内容!!!";
                return wResult;
            }

            if (wFPCRouteList.size() <= 0) {
                wResult.FaultCode += "导入失败：【Sheet1】工艺路线未保存成功!!!";
                return wResult;
            }

            //①工区信息
            Map<String, Object> wParams = new HashMap<String, Object>();
            List<FMCWorkArea> wFMCWorkAreaList = mFMCWorkAreaService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wFMCWorkAreaList == null || wFMCWorkAreaList.size() <= 0) {
                wResult.FaultCode += "导入失败：未获取到工区信息!!!";
                return wResult;
            }
            Map<String, Integer> wNameIDAreaMap =
                    wFMCWorkAreaList.stream().collect(Collectors.toMap(FMCWorkArea::getName
                            , FMCWorkArea::getID));

            Map<String, FMCWorkArea> wNameWorkAreaMap =
                    wFMCWorkAreaList.stream().collect(Collectors.toMap(FMCWorkArea::getName
                            , p -> p));
            //②工艺路线
            Map<String, Integer> wNameIDRouteMap =
                    wFPCRouteList.stream().collect(Collectors.toMap(FPCRoute::getName
                            , FPCRoute::getID));

            List<FPCRoutePart> wFPCRoutePartList = new ArrayList<>();
            FPCRoutePart wFPCRoutePart;
            for (int i = 0; i < wExcelSheetData.lineData.size(); i++) {
                if (i == 0) {
                    continue;
                }

                ExcelLineData wExcelLineData = wExcelSheetData.lineData.get(i);
                int wIndex = 0;

                //BOP编号
                String wCol1 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol1)) {
                    continue;
                }
                if (!wNameIDRouteMap.containsKey(wCol1)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet2】第【{0}】行数据有误，工艺路线【{1}】不存在!!!", i + 1, wCol1);
                    return wResult;
                }
                //工艺名称
                String wCol2 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol2)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet2】第【{0}】行数据有误，工艺名称不能为空!!!", i + 1);
                    return wResult;
                }
                //工区名称
                String wCol3 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol3)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet2】第【{0}】行数据有误，工区名称不能为空!!!", i + 1);
                    return wResult;
                }
                if (!wNameIDAreaMap.containsKey(wCol3)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet2】第【{0}】行数据有误，工区信息【{1}】不存在!!!", i + 1, wCol3);
                    return wResult;
                }
                //顺序
                String wCol4 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol4)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet2】第【{0}】行数据有误，顺序不能为空!!!", i + 1);
                    return wResult;
                }
                //前工艺
                String wCol5 = wExcelLineData.colData.get(wIndex++);
                //后工艺
                String wCol6 = wExcelLineData.colData.get(wIndex++);
                //描述信息
                String wCol7 = wExcelLineData.colData.get(wIndex++);

                wFPCRoutePart = new FPCRoutePart();
                wFPCRoutePart.Version = "";
                wFPCRoutePart.RouteID = wNameIDRouteMap.get(wCol1);
                wFPCRoutePart.WorkShopID = wNameWorkAreaMap.get(wCol3).WorkshopID;
                wFPCRoutePart.WorkAreaID = wNameIDAreaMap.get(wCol3);
                wFPCRoutePart.OrderID = StringUtils.parseInt(wCol4);
                wFPCRoutePart.Name = wCol2;
                wFPCRoutePart.setUserInfo(wLoginUser);
                wFPCRoutePart.Active = 0;
                wFPCRoutePart.PrevPartName = wCol5;
                wFPCRoutePart.NextPartName = wCol6;
                wFPCRoutePart.Description = wCol7;
                wFPCRoutePartList.add(wFPCRoutePart);
            }

            if (wFPCRoutePartList.size() > 0) {
                //保存工艺
                mFPCRoutePartService.UpdatePoList(wLoginUser, wFPCRoutePartList, wErrorCode);
                if (wFPCRoutePartList.stream().anyMatch(p -> p.ID <= 0)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet2】保存工艺失败!!!");
                    return wResult;
                }
                Map<String, Integer> wNameIDRoutePartMap =
                        wFPCRoutePartList.stream().collect(Collectors.toMap(FPCRoutePart::getName
                                , FPCRoutePart::getID));
                //设置前后工艺
                for (FPCRoutePart wFPCRoutePartItem : wFPCRoutePartList) {
                    //前工艺
                    if (StringUtils.isNotEmpty(wFPCRoutePartItem.PrevPartName)
                            && wNameIDRoutePartMap.containsKey(wFPCRoutePartItem.PrevPartName)) {
                        wFPCRoutePartItem.PrevPartID = wNameIDRoutePartMap.get(wFPCRoutePartItem.PrevPartName);
                    }
                    //后工艺
                    if (StringUtils.isNotEmpty(wFPCRoutePartItem.NextPartName)) {
                        List<Integer> wIDList = new ArrayList<>();
                        if (wFPCRoutePartItem.NextPartName.contains(",")) {
                            String[] wSplitList = wFPCRoutePartItem.NextPartName.split(",");
                            for (String wSplit : wSplitList) {
                                if (wNameIDRoutePartMap.containsKey(wSplit)) {
                                    wIDList.add(wNameIDRoutePartMap.get(wSplit));
                                }
                            }
                        } else if (wFPCRoutePartItem.NextPartName.contains("，")) {
                            String[] wSplitList = wFPCRoutePartItem.NextPartName.split("，");
                            for (String wSplit : wSplitList) {
                                if (wNameIDRoutePartMap.containsKey(wSplit)) {
                                    wIDList.add(wNameIDRoutePartMap.get(wSplit));
                                }
                            }
                        } else {
                            if (wNameIDRoutePartMap.containsKey(wFPCRoutePartItem.NextPartName)) {
                                wIDList.add(wNameIDRoutePartMap.get(wFPCRoutePartItem.NextPartName));
                            }
                        }
                        wFPCRoutePartItem.NextPartID = wIDList;
                    }
                }
                mFPCRoutePartService.UpdatePoList(wLoginUser, wFPCRoutePartList, wErrorCode);
            }

            wResult.Result = wFPCRoutePartList;

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("FPC_ImportRoute_RoutePart", e);
        }
        return wResult;

    }

    /**
     * 导入路线
     */
    private ServiceResult<List<FPCRoute>> FPC_ImportRoute_Line(BMSEmployee wLoginUser, ExcelSheetData wExcelSheetData) {
        ServiceResult<List<FPCRoute>> wResult = new ServiceResult<>();
        wResult.Result = new ArrayList<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            if (wExcelSheetData.lineData == null || wExcelSheetData.lineData.size() <= 1) {
                wResult.FaultCode += "导入失败：【Sheet1】无内容!!!";
                return wResult;
            }

            //①产品型号
            Map<String, Object> wParams = new HashMap<String, Object>();
            List<FPCProduct> wFPCProductList = mFPCProductService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wFPCProductList == null || wFPCProductList.size() <= 0) {
                wResult.FaultCode += "导入失败：未获取到产品信息!!!";
                return wResult;
            }
            Map<String, Integer> wCodeIDProductMap =
                    wFPCProductList.stream().collect(Collectors.toMap(FPCProduct::getCode
                            , FPCProduct::getID));
            //②产线信息
            List<FMCLine> wFMCLineList = mFMCLineService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wFMCLineList == null || wFMCLineList.size() <= 0) {
                wResult.FaultCode += "导入失败：未获取到产线信息!!!";
                return wResult;
            }
            Map<String, Integer> wNameIDLineMap =
                    wFMCLineList.stream().collect(Collectors.toMap(FMCLine::getName
                            , FMCLine::getID));
            //③客户信息
            List<CRMCustomer> wCRMCustomerList = mCRMCustomerService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wCRMCustomerList == null || wCRMCustomerList.size() <= 0) {
                wResult.FaultCode += "导入失败：未获取到客户信息!!!";
                return wResult;
            }
            Map<String, Integer> wNameIDCustomerMap =
                    wCRMCustomerList.stream().collect(Collectors.toMap(CRMCustomer::getName
                            , CRMCustomer::getID));
            //④产品工艺
            List<FPCRouteParent> wFPCRouteParentList = mFPCRouteParentService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wFPCRouteParentList == null || wFPCRouteParentList.size() <= 0) {
                wResult.FaultCode += "导入失败：未获取到产品工艺信息!!!";
                return wResult;
            }

            List<FPCRoute> wFPCRouteList = new ArrayList<>();
            FPCRoute wFPCRoute;
            for (int i = 0; i < wExcelSheetData.lineData.size(); i++) {
                if (i == 0) {
                    continue;
                }

                ExcelLineData wExcelLineData = wExcelSheetData.lineData.get(i);
                int wIndex = 0;

                //BOP编号
                String wCol1 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol1)) {
                    continue;
                }
                //版本号
                String wCol2 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol2)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet1】第【{0}】行数据有误，版本号不能为空!!!", i + 1);
                    return wResult;
                }
                //产品型号
                String wCol3 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol3)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet1】第【{0}】行数据有误，产品型号不能为空!!!", i + 1);
                    return wResult;
                }
                if (!wCodeIDProductMap.containsKey(wCol3)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet1】第【{0}】行数据有误，产品型号信息【{1}】不存在!!!", i + 1, wCol3);
                    return wResult;
                }
                int wProductID = wCodeIDProductMap.get(wCol3);
                //产线
                String wCol4 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol4)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet1】第【{0}】行数据有误，产线不能为空!!!", i + 1);
                    return wResult;
                }
                if (!wNameIDLineMap.containsKey(wCol4)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet1】第【{0}】行数据有误，产线信息【{1}】不存在!!!", i + 1, wCol4);
                    return wResult;
                }
                int wLineID = wNameIDLineMap.get(wCol4);
                //客户
                String wCol5 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol5)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet1】第【{0}】行数据有误，客户不能为空!!!", i + 1);
                    return wResult;
                }
                if (!wNameIDCustomerMap.containsKey(wCol5)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet1】第【{0}】行数据有误，客户信息【{1}】不存在!!!", i + 1, wCol5);
                    return wResult;
                }
                int wCustomerID = wNameIDCustomerMap.get(wCol5);
                //描述信息
                String wCol6 = wExcelLineData.colData.get(wIndex++);
                //根据`BOP编号、产品型号、产线、客户`查询产品工艺
                if (wFPCRouteParentList.stream().noneMatch(p -> p.Name.equals(wCol1) && p.ProductID == wProductID
                        && p.LineID == wLineID && p.CustomerID == wCustomerID)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：【Sheet1】第【{0}】行数据有误，产品工艺信息【{1}】不存在!!!", i + 1, wCol1);
                    return wResult;
                }

                //创建数据结构，添加到结果集
                wFPCRoute = new FPCRoute();
                wFPCRoute.BOPParentID =
                        wFPCRouteParentList.stream().filter(p -> p.Name.equals(wCol1) && p.ProductID == wProductID
                                && p.LineID == wLineID && p.CustomerID == wCustomerID).findFirst().get().ID;
                wFPCRoute.Version = wCol2;
                wFPCRoute.IsStandard = 0;
                wFPCRoute.Name = wCol1;
                wFPCRoute.Code = "";
                wFPCRoute.setUserInfo(wLoginUser);
                wFPCRoute.Active = 0;
                wFPCRoute.Description = wCol6;
                wFPCRoute.TypeID = FPCRouteType.RoutePartWorkArea.getValue();
                wFPCRoute.Status = FPCRouteStatus.SAVED.getValue();
                wFPCRouteList.add(wFPCRoute);
            }

            if (wFPCRouteList.size() > 0) {
                mFPCRouteService.UpdatePoList(wLoginUser, wFPCRouteList, wErrorCode);
            }
            wResult.Result = wFPCRouteList;

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("FPC_ImportRoute_Line", e);
        }
        return wResult;
    }

    @Override
    public ServiceResult<String> FPC_ExportRoute(BMSEmployee wLoginUser, int wRouteID) {
        ServiceResult<String> wResult = new ServiceResult<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            Map<String, Object> wParams = new HashMap<String, Object>();
            wParams.put("ID", wRouteID);
            FPCRoute wFPCRoute = mFPCRouteService.SelectPO(wLoginUser, wParams,
                    wErrorCode);

            if (wFPCRoute == null || wFPCRoute.ID <= 0) {
                wResult.FaultCode += ExceptionTypes.NotFound.getLabel();
                return wResult;
            }

            MyExcelSheet wMyExcelSheet1 = FPCRoute_GetMyExcelSheet1(wLoginUser, wFPCRoute);
            MyExcelSheet wMyExcelSheet2 = FPCRoute_GetMyExcelSheet2(wLoginUser, wFPCRoute);
            MyExcelSheet wMyExcelSheet3 = FPCRoute_GetMyExcelSheet3(wLoginUser, wFPCRoute);
            MyExcelSheet wMyExcelSheet4 = FPCRoute_GetMyExcelSheet4(wLoginUser, wFPCRoute);
            MyExcelSheet wMyExcelSheet5 = FPCRoute_GetMyExcelSheet5(wLoginUser, wFPCRoute);
            MyExcelSheet wMyExcelSheet6 = FPCRoute_GetMyExcelSheet6(wLoginUser, wFPCRoute);
            MyExcelSheet wMyExcelSheet7 = FPCRoute_GetMyExcelSheet7(wLoginUser, wFPCRoute);

            List<MyExcelSheet> wMyExcelSheetList = new ArrayList<MyExcelSheet>(Arrays.asList(wMyExcelSheet1,
                    wMyExcelSheet2, wMyExcelSheet3, wMyExcelSheet4, wMyExcelSheet5, wMyExcelSheet6, wMyExcelSheet7));

            wResult.Result = ExcelUtil.ExportData(wMyExcelSheetList, "工艺路线" + wFPCRoute.Version + "_");

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    private MyExcelSheet FPCRoute_GetMyExcelSheet7(BMSEmployee wLoginUser, FPCRoute wFPCRoute) {
        MyExcelSheet wResult = new MyExcelSheet();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            wResult.SheetName = "工序工装";
            wResult.TitleName = "";
            wResult.DataList = new ArrayList<>();
            wResult.HeaderList = new ArrayList<>(Arrays.asList("工序名称", "工装名称", "工装编码", "数量", "描述"));

            Map<String, Object> wParams = new HashMap<String, Object>();
            wParams.put("RouteID", wFPCRoute.ID);
            List<FPCRouteFrockTool> wFPCRouteFrockToolList = mFPCRouteFrockToolService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            wFPCRouteFrockToolList.sort(Comparator.comparing(FPCRouteFrockTool::getRoutePartOrder)
                    .thenComparing(FPCRouteFrockTool::getRoutePartPointOrder).thenComparing(FPCRouteFrockTool::getID));
            List<String> wValueList;
            for (FPCRouteFrockTool wFPCRouteFrockTool : wFPCRouteFrockToolList) {
                wValueList = new ArrayList<>();
                wValueList.add(wFPCRouteFrockTool.RoutePartPointName);
                wValueList.add(wFPCRouteFrockTool.FrockToolName);
                wValueList.add(wFPCRouteFrockTool.FrockToolCode);
                wValueList.add(String.valueOf(wFPCRouteFrockTool.Number));
                wValueList.add(wFPCRouteFrockTool.Description);
                wResult.DataList.add(wValueList);
            }
        } catch (Exception ex) {
            logger.error("FPCRoute_GetMyExcelSheet7", ex);
        }
        return wResult;
    }

    private MyExcelSheet FPCRoute_GetMyExcelSheet6(BMSEmployee wLoginUser, FPCRoute wFPCRoute) {
        MyExcelSheet wResult = new MyExcelSheet();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            wResult.SheetName = "工序量器具";
            wResult.TitleName = "";
            wResult.DataList = new ArrayList<>();
            wResult.HeaderList = new ArrayList<>(Arrays.asList("工序名称", "量器具名称", "量器具编码", "数量", "描述"));

            Map<String, Object> wParams = new HashMap<String, Object>();
            wParams.put("RouteID", wFPCRoute.ID);
            List<FPCRouteMeasureTool> wFPCRouteMeasureToolList = mFPCRouteMeasureToolService.SelectPOList(wLoginUser,
                    wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            wFPCRouteMeasureToolList.sort(Comparator.comparing(FPCRouteMeasureTool::getRoutePartOrder)
                    .thenComparing(FPCRouteMeasureTool::getRoutePartPointOrder).thenComparing(FPCRouteMeasureTool::getID));
            List<String> wValueList;
            for (FPCRouteMeasureTool wFPCRouteMeasureTool : wFPCRouteMeasureToolList) {
                wValueList = new ArrayList<>();
                wValueList.add(wFPCRouteMeasureTool.RoutePartPointName);
                wValueList.add(wFPCRouteMeasureTool.MeasureToolName);
                wValueList.add(wFPCRouteMeasureTool.MeasureToolCode);
                wValueList.add(String.valueOf(wFPCRouteMeasureTool.Number));
                wValueList.add(wFPCRouteMeasureTool.Description);
                wResult.DataList.add(wValueList);
            }
        } catch (Exception ex) {
            logger.error("FPCRoute_GetMyExcelSheet6", ex);
        }
        return wResult;
    }

    private MyExcelSheet FPCRoute_GetMyExcelSheet5(BMSEmployee wLoginUser, FPCRoute wFPCRoute) {
        MyExcelSheet wResult = new MyExcelSheet();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            wResult.SheetName = "工序物料";
            wResult.TitleName = "";
            wResult.DataList = new ArrayList<>();
            wResult.HeaderList = new ArrayList<>(Arrays.asList("工序名称", "物料名称", "物料编码", "物料数量", "描述"));

            Map<String, Object> wParams = new HashMap<String, Object>();
            wParams.put("RouteID", wFPCRoute.ID);
            List<MSSBOMItem> wMSSBOMItemList = mMSSBOMItemService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            wMSSBOMItemList.sort(Comparator.comparing(MSSBOMItem::getRoutePartOrder)
                    .thenComparing(MSSBOMItem::getRoutePartPointOrder).thenComparing(MSSBOMItem::getID));

            List<String> wValueList;
            for (MSSBOMItem wMSSBOMItem : wMSSBOMItemList) {
                wValueList = new ArrayList<>();
                wValueList.add(wMSSBOMItem.RoutePartPointName);
                wValueList.add(wMSSBOMItem.MaterialName);
                wValueList.add(wMSSBOMItem.MaterialNo);
                wValueList.add(String.valueOf(wMSSBOMItem.MaterialNumber));
                wValueList.add(wMSSBOMItem.Description);
                wResult.DataList.add(wValueList);
            }
        } catch (Exception ex) {
            logger.error("FPCRoute_GetMyExcelSheet5", ex);
        }
        return wResult;
    }

    private MyExcelSheet FPCRoute_GetMyExcelSheet4(BMSEmployee wLoginUser, FPCRoute wFPCRoute) {
        MyExcelSheet wResult = new MyExcelSheet();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            wResult.SheetName = "工序工步";
            wResult.TitleName = "";
            wResult.DataList = new ArrayList<>();
            wResult.HeaderList = new ArrayList<>(Arrays.asList("工序名称", "作业顺序", "作业工时", "作业内容",
                    "作业要求", "检验标准", "作业人数", "是否必填", "是否首检", "是否自检", "是否互检", "是否专检"));

            Map<String, Object> wParams = new HashMap<String, Object>();
            wParams.put("RouteID", wFPCRoute.ID);
            List<FPCRouteStep> wFPCRouteStepList = mFPCRouteStepService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            wFPCRouteStepList.sort(Comparator.comparing(FPCRouteStep::getRoutePartOrder)
                    .thenComparing(FPCRouteStep::getRoutePartPointOrder).thenComparing(FPCRouteStep::getStepOrder));

            List<String> wValueList;
            for (FPCRouteStep wFPCRouteStep : wFPCRouteStepList) {
                wValueList = new ArrayList<>();
                wValueList.add(wFPCRouteStep.RoutePartPointName);
                wValueList.add(String.valueOf(wFPCRouteStep.StepOrder));
                wValueList.add(String.valueOf(wFPCRouteStep.WorkTime));
                wValueList.add(wFPCRouteStep.WorkContent);
                wValueList.add(wFPCRouteStep.WorkRequirements);
                wValueList.add(wFPCRouteStep.CheckStandard);
                wValueList.add(String.valueOf(wFPCRouteStep.PersonNumber));
                wValueList.add(wFPCRouteStep.IsRequired == 1 ? "是" : "否");
                wValueList.add(wFPCRouteStep.IsFirstCheck == 1 ? "是" : "否");
                wValueList.add(wFPCRouteStep.IsSelfCheck == 1 ? "是" : "否");
                wValueList.add(wFPCRouteStep.IsMutualCheck == 1 ? "是" : "否");
                wValueList.add(wFPCRouteStep.IsSpecialCheck == 1 ? "是" : "否");
                wResult.DataList.add(wValueList);
            }
        } catch (Exception ex) {
            logger.error("FPCRoute_GetMyExcelSheet4", ex);
        }
        return wResult;
    }

    private MyExcelSheet FPCRoute_GetMyExcelSheet3(BMSEmployee wLoginUser, FPCRoute wFPCRoute) {
        MyExcelSheet wResult = new MyExcelSheet();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            wResult.SheetName = "工艺路线-第三层（工序）";
            wResult.TitleName = "";
            wResult.DataList = new ArrayList<>();
            wResult.HeaderList = new ArrayList<>(Arrays.asList("BOP编号", "工艺名称", "工序名称", "作业工位", "顺序", "前工序", "后工序",
                    "互检模式", "报工模式", "自动报工数量", "强制专检", "报工交接", "描述", "工件类型"));

            Map<String, Object> wParams = new HashMap<String, Object>();
            wParams.put("RouteID", wFPCRoute.ID);
            List<FPCRoutePartPoint> wFPCRoutePartPointList = mFPCRoutePartPointService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            wFPCRoutePartPointList.sort(Comparator.comparing(FPCRoutePartPoint::getRoutePartOrder)
                    .thenComparing(FPCRoutePartPoint::getOrderID));

            Map<Integer, String> wIDNameMap =
                    wFPCRoutePartPointList.stream().collect(Collectors.toMap(FPCRoutePartPoint::getID
                            , FPCRoutePartPoint::getName));

            wParams.clear();
            List<FMCStation> wFMCStationList = mFMCStationService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            Map<Integer, String> wIDNameStationMap =
                    wFMCStationList.stream().collect(Collectors.toMap(FMCStation::getID
                            , FMCStation::getName));

            for (FPCRoutePartPoint wFPCRoutePartPoint : wFPCRoutePartPointList) {
                if (wFPCRoutePartPoint.PrevPartPointName == null) {
                    wFPCRoutePartPoint.PrevPartPointName = "";
                }
                if (wFPCRoutePartPoint.NextPartPointID != null && wFPCRoutePartPoint.NextPartPointID.size() > 0) {
                    List<String> wNameList = new ArrayList<>();
                    for (int wPartPointID : wFPCRoutePartPoint.NextPartPointID) {
                        wNameList.add(wIDNameMap.get(wPartPointID));
                    }
                    wFPCRoutePartPoint.NextPartPointName = StringUtils.Join(",", wNameList);
                }
                if (wFPCRoutePartPoint.StationID != null && wFPCRoutePartPoint.StationID.size() > 0) {
                    List<String> wNameList = new ArrayList<>();
                    for (int wStationID : wFPCRoutePartPoint.StationID) {
                        wNameList.add(wIDNameStationMap.get(wStationID));
                    }
                    wFPCRoutePartPoint.StationName = StringUtils.Join(",", wNameList);
                }
            }

            List<String> wValueList;
            for (FPCRoutePartPoint wFPCRoutePartPoint : wFPCRoutePartPointList) {
                wValueList = new ArrayList<>();
                wValueList.add(wFPCRoute.BOPParentName);
                wValueList.add(wFPCRoutePartPoint.RoutePartName);
                wValueList.add(wFPCRoutePartPoint.Name);
                wValueList.add(wFPCRoutePartPoint.StationName);
                wValueList.add(String.valueOf(wFPCRoutePartPoint.OrderID));
                wValueList.add(wFPCRoutePartPoint.PrevPartPointName);
                wValueList.add(wFPCRoutePartPoint.NextPartPointName);
                wValueList.add(FPCMutualModel.getEnumType(wFPCRoutePartPoint.MutualModel).getLabel());
                wValueList.add(FPCTaskReportMode.getEnumType(wFPCRoutePartPoint.ReportMode).getLabel());
                wValueList.add(String.valueOf(wFPCRoutePartPoint.ReportFQTY));
                wValueList.add(wFPCRoutePartPoint.IsSpecialCheck == 1 ? "是" : "否");
                wValueList.add(wFPCRoutePartPoint.HandoverSemiProduct == 1 ? "是" : "否");
                wValueList.add(wFPCRoutePartPoint.Description);
                wValueList.add(PDMComponentTypes.getEnumType(wFPCRoutePartPoint.ComponentType).getLabel());
                wResult.DataList.add(wValueList);
            }
        } catch (Exception ex) {
            logger.error("FPCRoute_GetMyExcelSheet3", ex);
        }
        return wResult;
    }

    private MyExcelSheet FPCRoute_GetMyExcelSheet2(BMSEmployee wLoginUser, FPCRoute wFPCRoute) {
        MyExcelSheet wResult = new MyExcelSheet();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            wResult.SheetName = "工艺路线-第二层（工艺）";
            wResult.TitleName = "";
            wResult.DataList = new ArrayList<>();
            wResult.HeaderList = new ArrayList<>(Arrays.asList("BOP编号", "工艺名称", "工区名称", "顺序", "前工艺", "后工艺", "描述"));

            Map<String, Object> wParams = new HashMap<String, Object>();
            wParams.put("RouteID", wFPCRoute.ID);
            List<FPCRoutePart> wFPCRoutePartList = mFPCRoutePartService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            Map<Integer, String> wIDNameMap =
                    wFPCRoutePartList.stream().collect(Collectors.toMap(FPCRoutePart::getID
                            , FPCRoutePart::getName));

            //排序
            wFPCRoutePartList.sort(Comparator.comparing(FPCRoutePart::getOrderID));
            //翻译后工艺
            for (FPCRoutePart wFPCRoutePart : wFPCRoutePartList) {
                if (wFPCRoutePart.PrevPartName == null) {
                    wFPCRoutePart.PrevPartName = "";
                }
                if (wFPCRoutePart.NextPartID != null && wFPCRoutePart.NextPartID.size() > 0) {
                    List<String> wNameList = new ArrayList<>();
                    for (int wPartID : wFPCRoutePart.NextPartID) {
                        wNameList.add(wIDNameMap.get(wPartID));
                    }
                    wFPCRoutePart.NextPartName = StringUtils.Join(",", wNameList);
                }
            }

            List<String> wValueList;
            for (FPCRoutePart wFPCRoutePart : wFPCRoutePartList) {
                wValueList = new ArrayList<>();
                wValueList.add(wFPCRoute.BOPParentName);
                wValueList.add(wFPCRoutePart.Name);
                wValueList.add(wFPCRoutePart.WorkAreaName);
                wValueList.add(String.valueOf(wFPCRoutePart.OrderID));
                wValueList.add(wFPCRoutePart.PrevPartName);
                wValueList.add(wFPCRoutePart.NextPartName);
                wValueList.add(wFPCRoutePart.Description);
                wResult.DataList.add(wValueList);
            }
        } catch (Exception ex) {
            logger.error("FPCRoute_GetMyExcelSheet2", ex);
        }
        return wResult;
    }

    private MyExcelSheet FPCRoute_GetMyExcelSheet1(BMSEmployee wLoginUser, FPCRoute wFPCRoute) {
        MyExcelSheet wResult = new MyExcelSheet();
        try {
            wResult.SheetName = "工艺路线-第一层（路线）";
            wResult.TitleName = "";
            wResult.DataList = new ArrayList<>();
            wResult.HeaderList = new ArrayList<>(Arrays.asList("BOP编号", "版本号", "产品型号", "产线", "客户", "描述"));

            List<String> wValueList = new ArrayList<>(Arrays.asList(wFPCRoute.BOPParentName, wFPCRoute.Version,
                    wFPCRoute.ProductNo, wFPCRoute.LineName, wFPCRoute.CustomerName, wFPCRoute.Description));
            wResult.DataList.add(wValueList);
        } catch (Exception ex) {
            logger.error("FPCRoute_GetMyExcelSheet1", ex);
        }
        return wResult;
    }

    //endregion

    //region 工步

    @Override
    public ServiceResult<FPCRouteStep> FPC_RouteStepInfo(BMSEmployee wLoginUser, Map<String, Object> wParams) {
        ServiceResult<FPCRouteStep> wResult = new ServiceResult<>();
        wResult.Result = new FPCRouteStep();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            PoService<FPCRouteStep> mPoService = ORMUtils.GetPoService(FPCRouteStep.class);
            wResult.Result = mPoService.SelectPO(wLoginUser, wParams, wErrorCode);
            if (wResult.Result != null && wResult.Result.ID > 0) {
                PoService<FPCRouteStepQualification> fpcRouteStepQualificationPoService =
                        ORMUtils.GetPoService(FPCRouteStepQualification.class);
                Map<String, Object> wQMaps = new HashMap<String, Object>();
                wQMaps.put("RouteStepID", wResult.Result.ID);
                wResult.Result.QualificationList = fpcRouteStepQualificationPoService.SelectPOList(wLoginUser,
                        wQMaps
                        , Pagination.getMaxSize(),
                        wErrorCode);
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<FPCRoute>> FPC_QueryRouteAll(BMSEmployee wLoginUser, Map<String, Object> wParams,
                                                           Pagination wPagination) {
        ServiceResult<List<FPCRoute>> wResult = new ServiceResult<>();
        wResult.Result = new ArrayList<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            wResult.Result = mFPCRouteService.SelectPOList(wLoginUser, wParams, wPagination, wErrorCode);
            if (wResult.Result.size() > 0) {
                List<Integer> wRouteIDList =
                        wResult.Result.stream().map(p -> p.ID).distinct().collect(Collectors.toList());
                Map<Integer, Integer> wRouteSonMap = FPCRouteDAO.getInstance().FPC_QueryRouteSonMap(wLoginUser,
                        wRouteIDList, wErrorCode);
                for (FPCRoute wFPCRoute : wResult.Result) {
                    if (wRouteSonMap.containsKey(wFPCRoute.ID)) {
                        wFPCRoute.ItemCount = wRouteSonMap.get(wFPCRoute.ID);
                    }
                }
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<List<FPCRoutePartPoint>> FPC_QueryProductRoutePartPoint(BMSEmployee wLoginUser,
                                                                                 int wFactoryID, int wLineID,
                                                                                 int wCustomerID,
                                                                                 int wProductID,
                                                                                 Pagination wPagination) {
        ServiceResult<List<FPCRoutePartPoint>> wResult = new ServiceResult<>();
        wResult.Result = new ArrayList<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            FPCRoute wFPCRoute = FPCRouteDAO.getInstance().FPC_QueryRouteStandard(wLoginUser, wFactoryID, wLineID,
                    wCustomerID, wProductID, wErrorCode);

            if (wErrorCode.Result != 0) {
                wResult.AddFaultCode(wErrorCode);
                return wResult;
            }

            if (wFPCRoute == null || wFPCRoute.ID <= 0)
                return wResult;


            wResult.Result = FPCRoutePartPointDAO.getInstance().FPC_QueryRoutePartPointList(wLoginUser, wFPCRoute.ID,
                    wPagination, wErrorCode);

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    //endregion

    //region 工艺流程图

    @Override
    public ServiceResult<List<FPCFlowPart>> FPC_QueryFlowDataPart(BMSEmployee wLoginUser, int wRouteID,
                                                                  int wRoutePartID) {
        ServiceResult<List<FPCFlowPart>> wResult = new ServiceResult<>();
        wResult.Result = new ArrayList<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            //查询工艺路线图
            Map<String, Object> wParams;
            if (wRoutePartID <= 0) {
                wParams = new HashMap<>();
                wParams.put("RouteID", wRouteID);
                List<FPCRoutePart> wFPCRoutePartList = mFPCRoutePartService.SelectPOList(wLoginUser, wParams,
                        Pagination.getMaxSize(), wErrorCode);
                wResult.Result = FPCRouteDAO.getInstance().GetFlowPartList(wFPCRoutePartList);
                List<FPCFlowLine> wLineList = FPCRouteDAO.getInstance().GetFlowLineList(wFPCRoutePartList,
                        wResult.Result);
                wResult.CustomResult.put("LineList", wLineList);
            }
            //查询工艺工序路线图
            else {
                wParams = new HashMap<>();
                wParams.put("RouteID", wRouteID);
                wParams.put("RoutePartID", wRoutePartID);
                List<FPCRoutePartPoint> wFPCRoutePartPointList = mFPCRoutePartPointService.SelectPOList(wLoginUser,
                        wParams,
                        Pagination.getMaxSize(), wErrorCode);
                //转换结构
                List<FPCRoutePart> wList = new ArrayList<>();
                FPCRoutePart wFPCRoutePart;
                for (FPCRoutePartPoint wFPCRoutePartPoint : wFPCRoutePartPointList) {
                    wFPCRoutePart = new FPCRoutePart();
                    wFPCRoutePart.ID = wFPCRoutePartPoint.ID;
                    wFPCRoutePart.Name = wFPCRoutePartPoint.Name;
                    wFPCRoutePart.PrevPartID = wFPCRoutePartPoint.PrevPartPointID;
                    wFPCRoutePart.NextPartID = wFPCRoutePartPoint.NextPartPointID;
                    wFPCRoutePart.OrderID = wFPCRoutePartPoint.OrderID;
                    wFPCRoutePart.KeyProcess = wFPCRoutePartPoint.KeyProcess;
                    wList.add(wFPCRoutePart);
                }
                wResult.Result = FPCRouteDAO.getInstance().GetFlowPartList(wList);
                List<FPCFlowLine> wLineList = FPCRouteDAO.getInstance().GetFlowLineList(wList,
                        wResult.Result);
                wResult.CustomResult.put("LineList", wLineList);
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    //endregion

    //region 工艺工序

    @Override
    public ServiceResult<Integer> FPC_RoutePartPointActive(BMSEmployee wLoginUser, int wActive,
                                                           List<FPCRoutePartPoint> wFPCRoutePartPointList) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            Map<String, Object> wParams = new HashMap<String, Object>();

            List<FPCRouteStep> wFPCRouteStepList;
            for (FPCRoutePartPoint wFPCRoutePartPoint : wFPCRoutePartPointList) {
                //激活时，判断工序下是否存在已激活的工步，若没有，则报错
                if (wActive == 1) {
                    wParams.clear();
                    wParams.put("RoutePartPointID", wFPCRoutePartPoint.ID);
                    wParams.put("Active", 1);
                    wFPCRouteStepList = mFPCRouteStepService.SelectPOList(wLoginUser, wParams,
                            Pagination.getNewMaxSize(),
                            wErrorCode);
                    if (wFPCRouteStepList.size() == 0) {
                        wResult.FaultCode += StringUtils.Format("工序【{0}】下未配置激活的工步!", wFPCRoutePartPoint.Name);
                        return wResult;
                    }
                }

                wFPCRoutePartPoint.setUserInfo(wLoginUser);
                mFPCRoutePartPointService.ActivePO(wLoginUser, wFPCRoutePartPoint, wActive, wErrorCode);
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_RoutePartActive(BMSEmployee wLoginUser, int wActive,
                                                      List<FPCRoutePart> wFPCRoutePartList) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            Map<String, Object> wParams = new HashMap<String, Object>();

            List<FPCRoutePartPoint> wFPCRoutePartPointList;
            for (FPCRoutePart wFPCRoutePart : wFPCRoutePartList) {
                //激活时，判断工序下是否存在已激活的工步，若没有，则报错
                if (wActive == 1) {
                    wParams.clear();
                    wParams.put("RoutePartID", wFPCRoutePart.ID);
                    wParams.put("Active", 1);
                    wFPCRoutePartPointList = mFPCRoutePartPointService.SelectPOList(wLoginUser, wParams,
                            Pagination.getNewMaxSize(),
                            wErrorCode);
                    if (wFPCRoutePartPointList.size() == 0) {
                        wResult.FaultCode += StringUtils.Format("工艺【{0}】下未配置激活的工序!", wFPCRoutePart.Name);
                        return wResult;
                    }
                }

                wFPCRoutePart.setUserInfo(wLoginUser);
                mFPCRoutePartService.ActivePO(wLoginUser, wFPCRoutePart, wActive, wErrorCode);
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_RouteActive(BMSEmployee wLoginUser, int wActive,
                                                  List<FPCRoute> wFPCRouteList) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            Map<String, Object> wParams = new HashMap<String, Object>();

            List<FPCRoutePart> wFPCRoutePartList;
            for (FPCRoute wFPCRoute : wFPCRouteList) {

                //激活时，判断工序下是否存在已激活的工步，若没有，则报错
                if (wActive == 1) {
                    wParams.clear();
                    wParams.put("RouteID", wFPCRoute.ID);
                    wParams.put("Active", 1);
                    wFPCRoutePartList = mFPCRoutePartService.SelectPOList(wLoginUser, wParams,
                            Pagination.getNewMaxSize(),
                            wErrorCode);
                    if (wFPCRoutePartList.size() == 0) {
                        wResult.FaultCode += StringUtils.Format("工艺路线【{0}】下未配置激活的工艺集!", wFPCRoute.Version);
                        return wResult;
                    }
                }

                //禁用时，当前版本不允许禁用
                if (wActive == 2 && wFPCRoute.IsStandard == 1) {
                    wResult.FaultCode += StringUtils.Format("工艺路线【{0}】已设置为当前版本，不允许禁用!", wFPCRoute.Version);
                    return wResult;
                }

                wFPCRoute.setUserInfo(wLoginUser);
                mFPCRouteService.ActivePO(wLoginUser, wFPCRoute, wActive, wErrorCode);
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_RouteParentActive(BMSEmployee wLoginUser, int wActive,
                                                        List<FPCRouteParent> wFPCRouteParentList) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            Map<String, Object> wParams = new HashMap<String, Object>();

            for (FPCRouteParent wFPCRouteParent : wFPCRouteParentList) {
                //激活时，判断该产品工艺是否有当前版本工艺路线，若没有，则报错
                if (wActive == 1 && wFPCRouteParent.IsRoutID != 1) {
                    wResult.FaultCode += StringUtils.Format("产品工艺【{0}】下未设置当前版本的工艺路线!", wFPCRouteParent.Name);
                    return wResult;
                }

                wFPCRouteParent.setUserInfo(wLoginUser);
                mFPCRouteParentService.ActivePO(wLoginUser, wFPCRouteParent, wActive, wErrorCode);
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    //endregion

    //region 工艺路线审批


    @Override
    public ServiceResult<Integer> FPC_RouteCopy(BMSEmployee wLoginUser, int wRouteID, String wNewVersion,
                                                int wIsCopyParameters, int wBOPParentID, int wActive) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            //①查询工艺路线
            Map<String, Object> wParams = new HashMap<String, Object>();
            wParams.put("ID", wRouteID);
            FPCRoute wFPCRoute = mFPCRouteService.SelectPO(wLoginUser, wParams,
                    wErrorCode);
            if (wFPCRoute == null || wFPCRoute.ID <= 0) {
                wResult.FaultCode += ExceptionTypes.DBSQL.getLabel();
                return wResult;
            }
            //②判断新版本号是否重复
            int wNewBOPParentID = wFPCRoute.BOPParentID;
            if (wBOPParentID > 0) {
                wNewBOPParentID = wBOPParentID;
            }
            wParams.clear();
            wParams.put("BOPParentID", wNewBOPParentID);
            wParams.put("VersionEQ", wNewVersion);
            List<FPCRoute> wFPCRouteList = mFPCRouteService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wFPCRouteList != null && wFPCRouteList.size() > 0) {
                wResult.FaultCode += StringUtils.Format("复制失败：版本号【{0}】已存在!!!", wNewVersion);
                return wResult;
            }
            //查询新版工艺bop
            wParams.clear();
            wParams.put("ID", wNewBOPParentID);
            FPCRouteParent fpcRouteParent = mFPCRouteParentService.SelectPO(wLoginUser, wParams,
                    wErrorCode);

            //③复制工艺路线
            wFPCRoute.ID = 0;
            wFPCRoute.Code = "";
            wFPCRoute.Version = wNewVersion;
            wFPCRoute.Status = FPCRouteStatus.SAVED.getValue();
            wFPCRoute.Active = wActive;
            wFPCRoute.IsStandard = 0;
            wFPCRoute.BOPParentID = wNewBOPParentID;
            wFPCRoute.setUserInfo(wLoginUser);
            wFPCRoute.EditTime = Calendar.getInstance();
            int wAffectRows = mFPCRouteService.UpdatePo(wLoginUser, wFPCRoute, wErrorCode);
            if (wAffectRows <= 0) {
                wResult.FaultCode += "1934:" + ExceptionTypes.DBSQL.getLabel();
                return wResult;
            }

            //复制参数（工艺、质量、环境）
            wParams.clear();
            wParams.put("RouteID", wRouteID);
            List<FPCProductParameter> fpcProductParameters = mFPCProductParameterService.SelectPOList(wLoginUser,
                    wParams, Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wIsCopyParameters == 1) {
                for (FPCProductParameter fpcProductParameter : fpcProductParameters) {
                    fpcProductParameter.HisProductParameterID = fpcProductParameter.ID;
                    fpcProductParameter.Code = "";
                    fpcProductParameter.RouteID = wFPCRoute.ID;
                    fpcProductParameter.ID = 0;
                    fpcProductParameter.Active = wActive;
                    fpcProductParameter.ProductID = fpcRouteParent.ProductID;
                    fpcProductParameter.setUserInfo(wLoginUser);
                    fpcProductParameter.EditTime = Calendar.getInstance();
                    mFPCProductParameterService.UpdatePo(wLoginUser, fpcProductParameter, wErrorCode);
                }
            }

            //⑤复制工艺集
            wParams.clear();
            wParams.put("RouteID", wRouteID);
            List<FPCRoutePart> wFPCRoutePartList = mFPCRoutePartService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            List<FPCRoutePart> wFPCRoutePartConeList = CloneTool.CloneArray(wFPCRoutePartList, FPCRoutePart.class);
            List<FPCRoutePartPoint> wFPCRoutePartPointAllList = new ArrayList<>();
            List<FPCRoutePartPoint> wFPCRoutePartPointAllCloneList = new ArrayList<>();
            for (FPCRoutePart wFPCRoutePart : wFPCRoutePartList) {
                int wOldRoutePartID = wFPCRoutePart.ID;
                wFPCRoutePart.ID = 0;
                wFPCRoutePart.Code = "";
                wFPCRoutePart.RouteID = wFPCRoute.ID;
                wFPCRoutePart.Active = wActive;
                wFPCRoutePart.setUserInfo(wLoginUser);
                wFPCRoutePart.EditTime = Calendar.getInstance();
                wAffectRows = mFPCRoutePartService.UpdatePo(wLoginUser, wFPCRoutePart, wErrorCode);
                if (wAffectRows <= 0) {
                    wResult.FaultCode += "1950:" + ExceptionTypes.DBSQL.getLabel();
                    return wResult;
                }
                //⑦复制工序集
                wParams.clear();
                wParams.put("RouteID", wRouteID);
                wParams.put("RoutePartID", wOldRoutePartID);
                List<FPCRoutePartPoint> wFPCRoutePartPointList = mFPCRoutePartPointService.SelectPOList(wLoginUser,
                        wParams, Pagination.getNewMaxSize(),
                        wErrorCode);
                wFPCRoutePartPointAllList.addAll(wFPCRoutePartPointList);
                wFPCRoutePartPointAllCloneList.addAll(CloneTool.CloneArray(wFPCRoutePartPointList,
                        FPCRoutePartPoint.class));
                for (FPCRoutePartPoint wFPCRoutePartPoint : wFPCRoutePartPointList) {
                    int wOldRoutePartPointID = wFPCRoutePartPoint.ID;
                    wFPCRoutePartPoint.ID = 0;
                    wFPCRoutePartPoint.Code = "";
                    wFPCRoutePartPoint.RouteID = wFPCRoute.ID;
                    wFPCRoutePartPoint.RoutePartID = wFPCRoutePart.ID;
                    wFPCRoutePartPoint.Active = wActive;
                    wFPCRoutePartPoint.setUserInfo(wLoginUser);
                    wFPCRoutePartPoint.EditTime = Calendar.getInstance();
                    wAffectRows = mFPCRoutePartPointService.UpdatePo(wLoginUser, wFPCRoutePartPoint, wErrorCode);
                    if (wAffectRows <= 0) {
                        wResult.FaultCode += "1968:" + ExceptionTypes.DBSQL.getLabel();
                        return wResult;
                    }
                    //⑧复制工装
                    wParams.clear();
                    wParams.put("RoutePartPointID", wOldRoutePartPointID);
                    List<FPCRouteFrockTool> wFPCRouteFrockToolList =
                            mFPCRouteFrockToolService.SelectPOList(wLoginUser,
                                    wParams, Pagination.getNewMaxSize(),
                                    wErrorCode);
                    for (FPCRouteFrockTool wFPCRouteFrockTool : wFPCRouteFrockToolList) {
                        wFPCRouteFrockTool.ID = 0;
                        wFPCRouteFrockTool.Code = "";
                        wFPCRouteFrockTool.RouteID = wFPCRoute.ID;
                        wFPCRouteFrockTool.RoutePartID = wFPCRoutePart.ID;
                        wFPCRouteFrockTool.RoutePartPointID = wFPCRoutePartPoint.ID;
                        wFPCRouteFrockTool.Active = wActive;
                        wFPCRouteFrockTool.setUserInfo(wLoginUser);
                        wFPCRouteFrockTool.EditTime = Calendar.getInstance();
                        wAffectRows = mFPCRouteFrockToolService.UpdatePo(wLoginUser, wFPCRouteFrockTool,
                                wErrorCode);
                        if (wAffectRows <= 0) {
                            wResult.FaultCode += "1985:" + ExceptionTypes.DBSQL.getLabel();
                            return wResult;
                        }
                    }
                    //⑨复制量器具
                    wParams.clear();
                    wParams.put("RoutePartPointID", wOldRoutePartPointID);
                    List<FPCRouteMeasureTool> wFPCRouteMeasureToolList =
                            mFPCRouteMeasureToolService.SelectPOList(wLoginUser,
                                    wParams, Pagination.getNewMaxSize(),
                                    wErrorCode);
                    for (FPCRouteMeasureTool wFPCRouteMeasureTool : wFPCRouteMeasureToolList) {
                        wFPCRouteMeasureTool.ID = 0;
                        wFPCRouteMeasureTool.Code = "";
                        wFPCRouteMeasureTool.RouteID = wFPCRoute.ID;
                        wFPCRouteMeasureTool.RoutePartID = wFPCRoutePart.ID;
                        wFPCRouteMeasureTool.RoutePartPointID = wFPCRoutePartPoint.ID;
                        wFPCRouteMeasureTool.Active = wActive;
                        wFPCRouteMeasureTool.setUserInfo(wLoginUser);
                        wFPCRouteMeasureTool.EditTime = Calendar.getInstance();
                        wAffectRows = mFPCRouteMeasureToolService.UpdatePo(wLoginUser, wFPCRouteMeasureTool,
                                wErrorCode);
                        if (wAffectRows <= 0) {
                            wResult.FaultCode += "2004:" + ExceptionTypes.DBSQL.getLabel();
                            return wResult;
                        }
                    }
                    //⑩复制工序-工艺参数/复制环境参数
                    if (wIsCopyParameters == 1) {
                        wParams.clear();
                        wParams.put("RoutePartPointID", wOldRoutePartPointID);
                        List<FPCRoutePartPointParameter> wFPCRoutePartPointParameterList =
                                mFPCRoutePartPointParameterService.SelectPOList(wLoginUser,
                                        wParams, Pagination.getNewMaxSize(),
                                        wErrorCode);
                        for (FPCRoutePartPointParameter wFPCRoutePartPointParameter : wFPCRoutePartPointParameterList) {
                            wFPCRoutePartPointParameter.ID = 0;
                            wFPCRoutePartPointParameter.Code = "";
                            wFPCRoutePartPointParameter.RoutePartPointID = wFPCRoutePartPoint.ID;
                            wFPCRoutePartPointParameter.Active = wActive;
                            wFPCRoutePartPointParameter.setUserInfo(wLoginUser);
                            wFPCRoutePartPointParameter.EditTime = Calendar.getInstance();

                            Optional<FPCProductParameter> first =
                                    fpcProductParameters.stream().filter(p -> p.HisProductParameterID == wFPCRoutePartPointParameter.ProductParameter).findFirst();
                            first.ifPresent(fpcProductParameter -> wFPCRoutePartPointParameter.ProductParameter =
                                    fpcProductParameter.ID);

                            wAffectRows = mFPCRoutePartPointParameterService.UpdatePo(wLoginUser,
                                    wFPCRoutePartPointParameter, wErrorCode);
                            if (wAffectRows <= 0) {
                                wResult.FaultCode += "2022:" + ExceptionTypes.DBSQL.getLabel();
                                return wResult;
                            }
                        }
                    }
                    //③复制工序BOM
                    wParams.clear();
                    wParams.put("RoutePartPointID", wOldRoutePartPointID);
                    List<MSSBOMItem> wMSSBOMItemList = mMSSBOMItemService.SelectPOList(wLoginUser, wParams,
                            Pagination.getNewMaxSize(), wErrorCode);
                    for (MSSBOMItem wMSSBOMItem : wMSSBOMItemList) {
                        wMSSBOMItem.ID = 0;
                        wMSSBOMItem.Code = "";
                        wMSSBOMItem.RouteID = wFPCRoute.ID;
                        wMSSBOMItem.RoutePartID = wFPCRoutePart.ID;
                        wMSSBOMItem.RoutePartPointID = wFPCRoutePartPoint.ID;
                        wMSSBOMItem.Active = wActive;
                        wMSSBOMItem.setUserInfo(wLoginUser);
                        wMSSBOMItem.EditTime = Calendar.getInstance();
                        wAffectRows = mMSSBOMItemService.UpdatePo(wLoginUser, wMSSBOMItem,
                                wErrorCode);
                        if (wAffectRows <= 0) {
                            wResult.FaultCode += "2040:" + ExceptionTypes.DBSQL.getLabel();
                            return wResult;
                        }
                    }
                    //①复制工步
                    wParams.clear();
                    wParams.put("RoutePartPointID", wOldRoutePartPointID);
                    List<FPCRouteStep> wFPCRouteStepList = mFPCRouteStepService.SelectPOList(wLoginUser, wParams,
                            Pagination.getNewMaxSize(), wErrorCode);
                    for (FPCRouteStep wFPCRouteStep : wFPCRouteStepList) {
                        int wOldRouteStepID = wFPCRouteStep.ID;
                        wFPCRouteStep.ID = 0;
                        wFPCRouteStep.Code = "";
                        wFPCRouteStep.RouteID = wFPCRoute.ID;
                        wFPCRouteStep.RoutePartID = wFPCRoutePart.ID;
                        wFPCRouteStep.RoutePartPointID = wFPCRoutePartPoint.ID;
                        wFPCRouteStep.Active = wActive;
                        wFPCRouteStep.setUserInfo(wLoginUser);
                        wFPCRouteStep.EditTime = Calendar.getInstance();
                        if (wIsCopyParameters == 1) {
                            Optional<FPCProductParameter> first =
                                    fpcProductParameters.stream().filter(p -> p.HisProductParameterID == wFPCRouteStep.ProductParameter).findFirst();
                            first.ifPresent(fpcProductParameter -> wFPCRouteStep.ProductParameter =
                                    fpcProductParameter.ID);
                        } else {
                            wFPCRouteStep.ProductParameter = 0;
                        }

                        wAffectRows = mFPCRouteStepService.UpdatePo(wLoginUser, wFPCRouteStep,
                                wErrorCode);
                        if (wAffectRows <= 0) {
                            wResult.FaultCode += "2059:" + ExceptionTypes.DBSQL.getLabel();
                            return wResult;
                        }
                        //②复制工步资质
                        wParams.clear();
                        wParams.put("RouteStepID", wOldRouteStepID);
                        List<FPCRouteStepQualification> wFPCRouteStepQualificationList =
                                mFPCRouteStepQualificationService.SelectPOList(wLoginUser, wParams,
                                        Pagination.getNewMaxSize(),
                                        wErrorCode);
                        for (FPCRouteStepQualification wFPCRouteStepQualification :
                                wFPCRouteStepQualificationList) {
                            wFPCRouteStepQualification.ID = 0;
                            wFPCRouteStepQualification.Code = "";
                            wFPCRouteStepQualification.RouteStepID = wFPCRouteStep.ID;
                            wFPCRouteStepQualification.Active = wActive;
                            wFPCRouteStepQualification.setUserInfo(wLoginUser);
                            wFPCRouteStepQualification.EditTime = Calendar.getInstance();
                            wAffectRows = mFPCRouteStepQualificationService.UpdatePo(wLoginUser,
                                    wFPCRouteStepQualification,
                                    wErrorCode);
                            if (wAffectRows <= 0) {
                                wResult.FaultCode += "2076:" + ExceptionTypes.DBSQL.getLabel();
                                return wResult;
                            }
                        }
                    }
                }
            }
            //维护工艺集连线关系
            Map<Integer, String> wIDNameMapClone =
                    wFPCRoutePartConeList.stream().collect(Collectors.toMap(FPCRoutePart::getID
                            , FPCRoutePart::getName));
            Map<String, Integer> wNameIDMap =
                    wFPCRoutePartList.stream().collect(Collectors.toMap(FPCRoutePart::getName
                            , FPCRoutePart::getID));
            List<Integer> wNextIDList;
            for (FPCRoutePart wFPCRoutePart : wFPCRoutePartList) {
                if (wFPCRoutePart.PrevPartID > 0) {
                    wFPCRoutePart.PrevPartID = wNameIDMap.get(wIDNameMapClone.get(wFPCRoutePart.PrevPartID));
                }
                if (wFPCRoutePart.NextPartID == null || wFPCRoutePart.NextPartID.size() <= 0) {
                    continue;
                }
                wNextIDList = new ArrayList<>();
                for (int wNextPartID : wFPCRoutePart.NextPartID) {
                    wNextIDList.add(wNameIDMap.get(wIDNameMapClone.get(wNextPartID)));
                }
                wFPCRoutePart.NextPartID = wNextIDList;
            }
            mFPCRoutePartService.UpdatePoList(wLoginUser, wFPCRoutePartList, wErrorCode);
            //维护工序集连线关系
            Map<Integer, String> wIDNamePartPointMapClone =
                    wFPCRoutePartPointAllCloneList.stream().collect(Collectors.toMap(FPCRoutePartPoint::getID
                            , FPCRoutePartPoint::getName));
            Map<String, Integer> wNameIDPartPointMap =
                    wFPCRoutePartPointAllList.stream().collect(Collectors.toMap(FPCRoutePartPoint::getName
                            , FPCRoutePartPoint::getID));
            for (FPCRoutePartPoint wFPCRoutePartPoint : wFPCRoutePartPointAllList) {
                if (wFPCRoutePartPoint.PrevPartPointID > 0) {
                    wFPCRoutePartPoint.PrevPartPointID =
                            wNameIDPartPointMap.get(wIDNamePartPointMapClone.get(wFPCRoutePartPoint.PrevPartPointID));
                }
                if (wFPCRoutePartPoint.NextPartPointID == null || wFPCRoutePartPoint.NextPartPointID.size() <= 0) {
                    continue;
                }
                wNextIDList = new ArrayList<>();
                for (int wNextPartPointID : wFPCRoutePartPoint.NextPartPointID) {
                    wNextIDList.add(wNameIDPartPointMap.get(wIDNamePartPointMapClone.get(wNextPartPointID)));
                }
                wFPCRoutePartPoint.NextPartPointID = wNextIDList;
            }
            mFPCRoutePartPointService.UpdatePoList(wLoginUser, wFPCRoutePartPointAllList, wErrorCode);

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    //endregion

    //region 产品信息

    @Override
    public ServiceResult<Integer> FPC_ImportProduct(BMSEmployee wLoginUser, ExcelData wExcelData) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            if (wExcelData == null || wExcelData.sheetData == null || wExcelData.sheetData.size() <= 0) {
                wResult.FaultCode += "导入失败：Excel格式错误!!!";
                return wResult;
            }

            ExcelSheetData wExcelSheetData = wExcelData.sheetData.get(0);
            if (wExcelSheetData.lineData == null || wExcelSheetData.lineData.size() <= 1) {
                wResult.FaultCode += "导入失败：Excel无内容!!!";
                return wResult;
            }

            //①产品分组
            Map<String, Object> wParams = new HashMap<String, Object>();
            List<FPCProductGroup> wFPCProductGroupList = mFPCProductGroupService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wFPCProductGroupList == null || wFPCProductGroupList.size() <= 0) {
                wResult.FaultCode += "导入失败：未获取到产品分组信息!!!";
                return wResult;
            }
            Map<String, Integer> wNameIDGroupMap =
                    wFPCProductGroupList.stream().collect(Collectors.toMap(FPCProductGroup::getName
                            , FPCProductGroup::getID));

            //②产品类型
            List<FPCProductType> wFPCProductTypeList = mFPCProductTypeService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wFPCProductTypeList == null || wFPCProductTypeList.size() <= 0) {
                wResult.FaultCode += "导入失败：未获取到产品类型信息!!!";
                return wResult;
            }

            Map<String, Integer> wNameIDTypeMap =
                    wFPCProductTypeList.stream().collect(Collectors.toMap(FPCProductType::getName
                            , FPCProductType::getID));

            List<FPCProduct> wFPCProductList = new ArrayList<>();
            FPCProduct wFPCProduct;
            for (int i = 0; i < wExcelSheetData.lineData.size(); i++) {
                if (i == 0) {
                    continue;
                }

                ExcelLineData wExcelLineData = wExcelSheetData.lineData.get(i);

                //产品型号
                String wCol1 = wExcelLineData.colData.get(0);
                if (StringUtils.isEmpty(wCol1)) {
                    continue;
                }
                //产品名称
                String wCol2 = wExcelLineData.colData.get(1);
                if (StringUtils.isEmpty(wCol2)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，产品名称不能为空!!!", i + 1);
                    return wResult;
                }
                //产品分组
                String wCol3 = wExcelLineData.colData.get(2);
                if (StringUtils.isEmpty(wCol3)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，产品分组不能为空!!!", i + 1);
                    return wResult;
                }
                if (!wNameIDGroupMap.containsKey(wCol3)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，产品分组信息【{1}】不存在!!!", i + 1, wCol3);
                    return wResult;
                }
                //产品类型
                String wCol4 = wExcelLineData.colData.get(3);
                if (StringUtils.isEmpty(wCol4)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，产品类型不能为空!!!", i + 1);
                    return wResult;
                }
                if (!wNameIDTypeMap.containsKey(wCol4)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，产品类型信息【{1}】不存在!!!", i + 1, wCol4);
                    return wResult;
                }
                //描述信息
                String wCol5 = wExcelLineData.colData.get(4);
                wFPCProduct = new FPCProduct();
                wFPCProduct.Code = wCol1;
                wFPCProduct.Name = wCol2;
                wFPCProduct.ProductGroupID = wNameIDGroupMap.get(wCol3);
                wFPCProduct.ProductTypeID = wNameIDTypeMap.get(wCol4);
                wFPCProduct.Description = wCol5;
                wFPCProduct.setUserInfo(wLoginUser);
                wFPCProduct.Active = 0;
                wFPCProduct.ComponentNumber = 1;
                wFPCProduct.SimplifiedCode = "";
                wFPCProductList.add(wFPCProduct);
            }
            mFPCProductService.UpdatePoList(wLoginUser, wFPCProductList, wErrorCode);

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    //endregion

    //region 产品参数

    @Override
    public ServiceResult<Integer> FPC_ProductParameterImport(BMSEmployee wLoginUser, ExcelData wExcelData,
                                                             int routeID, int paramType) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            if (wExcelData == null || wExcelData.sheetData == null || wExcelData.sheetData.size() <= 0) {
                wResult.FaultCode += "导入失败：Excel格式错误!!!";
                return wResult;
            }

            ExcelSheetData wExcelSheetData = wExcelData.sheetData.get(0);
            if (wExcelSheetData.lineData == null || wExcelSheetData.lineData.size() <= 1) {
                wResult.FaultCode += "导入失败：Excel无内容!!!";
                return wResult;
            }

            //查询工艺路线
            Map<String, Object> wParams = new HashMap<String, Object>();
            wParams.put("ID", routeID);
            FPCRoute wFPCRoute = mFPCRouteService.SelectPO(wLoginUser, wParams,
                    wErrorCode);
            if (wFPCRoute == null || wFPCRoute.ID <= 0) {
                wResult.FaultCode += "导入失败：工艺路线不存在!!!";
                return wResult;
            }

            //单位列表
            wParams.clear();
            List<MSSUnit> wMSSUnitList = mMSSUnitService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wMSSUnitList == null || wMSSUnitList.size() <= 0) {
                wResult.FaultCode += "导入失败：未获取到单位信息!!!";
                return wResult;
            }
            Map<String, Integer> wCodeIDUnitMap =
                    wMSSUnitList.stream().collect(Collectors.toMap(MSSUnit::getCode
                            , MSSUnit::getID));

            //工位列表
            wParams.clear();
            List<FMCStation> wFMCStationList = mFMCStationService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wFMCStationList == null || wFMCStationList.size() <= 0) {
                wResult.FaultCode += "导入失败：未获取到工位信息!!!";
                return wResult;
            }
            Map<String, Integer> wNameIDStationMap =
                    wFMCStationList.stream().collect(Collectors.toMap(FMCStation::getName
                            , FMCStation::getID));

            List<FPCProductParameter> wFPCProductParameterList = new ArrayList<>();
            FPCProductParameter wFPCProductParameter;
            for (int i = 0; i < wExcelSheetData.lineData.size(); i++) {
                if (i == 0) {
                    continue;
                }

                ExcelLineData wExcelLineData = wExcelSheetData.lineData.get(i);
                int wIndex = 0;

                //参数名称
                String wCol1 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol1)) {
                    continue;
                }
                //参数编码
                String wCol2 = wExcelLineData.colData.get(wIndex++);
                //标准类型
                String wCol33 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol33)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，标准类型不能为空!!!", i + 1);
                    return wResult;
                }
                if (FPCStandardType.getEnumValue(wCol33) < 0) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，标准类型【{1}】输入值不合法!!!", i + 1, wCol33);
                    return wResult;
                }
                //下限值
                String wCol3 = wExcelLineData.colData.get(wIndex++);
                //上限值
                String wCol4 = wExcelLineData.colData.get(wIndex++);
                //标准值（理论值）
                String wCol5 = wExcelLineData.colData.get(wIndex++);
                //单位
                String wCol6 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isNotEmpty(wCol6) && !wCodeIDUnitMap.containsKey(wCol6)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，单位信息【{1}】不存在!!!", i + 1, wCol6);
                    return wResult;
                }
                int wUnitID = 0;
                if (StringUtils.isNotEmpty(wCol6)) {
                    wUnitID = wCodeIDUnitMap.get(wCol6);
                }
                //工位
                String wCol88 = wExcelLineData.colData.get(wIndex++);
                List<Integer> wStationIDList = new ArrayList<>();
                if (StringUtils.isNotEmpty(wCol88)) {
                    if (wCol88.contains(",")) {
                        String[] wSplits = wCol88.split(",");
                        for (String wSplit : wSplits) {
                            if (!wNameIDStationMap.containsKey(wSplit)) {
                                wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，工位信息【{1}】不存在!!!", i + 1,
                                        wSplit);
                                return wResult;
                            }
                            wStationIDList.add(wNameIDStationMap.get(wSplit));
                        }
                    } else if (wCol88.contains("，")) {
                        String[] wSplits = wCol88.split("，");
                        for (String wSplit : wSplits) {
                            if (!wNameIDStationMap.containsKey(wSplit)) {
                                wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，工位信息【{1}】不存在!!!", i + 1,
                                        wSplit);
                                return wResult;
                            }
                            wStationIDList.add(wNameIDStationMap.get(wSplit));
                        }
                    } else {
                        if (!wNameIDStationMap.containsKey(wCol88)) {
                            wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，工位信息【{1}】不存在!!!", i + 1,
                                    wCol88);
                            return wResult;
                        }
                        wStationIDList.add(wNameIDStationMap.get(wCol88));
                    }
                }
                //采集编号
                String wCol8 = wExcelLineData.colData.get(wIndex++);
                //默认值
                String wCol99 = wExcelLineData.colData.get(wIndex++);
                //备注
                String wCol7 = wExcelLineData.colData.get(wIndex++);
                //控制下限值
                String wCol9 = wExcelLineData.colData.size() >= 13 ? wExcelLineData.colData.get(wIndex++) : "";
                //控制上限值
                String wCol10 = wExcelLineData.colData.size() >= 13 ? wExcelLineData.colData.get(wIndex++) : "";

                wFPCProductParameter = new FPCProductParameter();
                wFPCProductParameter.Name = wCol1;
                wFPCProductParameter.Code = wCol2;
                wFPCProductParameter.RouteID = routeID;
                wFPCProductParameter.ParamType = paramType;
                wFPCProductParameter.StandardType = FPCStandardType.getEnumValue(wCol33);
                wFPCProductParameter.LowerTolerance = StringUtils.parseDouble(wCol3);
                wFPCProductParameter.UpperTolerance = StringUtils.parseDouble(wCol4);
                wFPCProductParameter.TheoreticalValue = wCol5;
                wFPCProductParameter.UnitID = wUnitID;
                wFPCProductParameter.Description = wCol7;
                wFPCProductParameter.ProductID = wFPCRoute.ProductID;
                wFPCProductParameter.StationID = wStationIDList;
                wFPCProductParameter.DefaultValue = wCol99;
                wFPCProductParameter.CollectionNumber = wCol8;
                wFPCProductParameter.ControlLeftValue = StringUtils.parseDouble(wCol9);
                wFPCProductParameter.ControlRightValue = StringUtils.parseDouble(wCol10);
                wFPCProductParameterList.add(wFPCProductParameter);
            }
            mFPCProductParameterService.UpdatePoList(wLoginUser, wFPCProductParameterList, wErrorCode);

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("FPC_ProductParameterImport", e);
        }
        return wResult;

    }

    @Override
    public ServiceResult<List<FPCProductParameter>> FPC_QueryToAddList(BMSEmployee wLoginUser, int wRoutePartPointID,
                                                                       FPCParamType wFPCParamType,
                                                                       int wRoutePartPointParamID) {
        ServiceResult<List<FPCProductParameter>> wResult = new ServiceResult<>();
        wResult.Result = new ArrayList<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            //①查询工艺工序
            Map<String, Object> wParams = new HashMap<String, Object>();
            wParams.put("ID", wRoutePartPointID);
            FPCRoutePartPoint wFPCRoutePartPoint = mFPCRoutePartPointService.SelectPO(wLoginUser, wParams,
                    wErrorCode);
            if (wFPCRoutePartPoint == null || wFPCRoutePartPoint.ID <= 0) {
                return wResult;
            }
            //②查询产品参数
            wParams.clear();
            wParams.put("RouteID", wFPCRoutePartPoint.RouteID);
            wParams.put("ParamType", wFPCParamType.getValue());
            wParams.put("Active", 1);
            List<FPCProductParameter> wFPCProductParameterList = mFPCProductParameterService.SelectPOList(wLoginUser,
                    wParams, Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wFPCProductParameterList == null || wFPCProductParameterList.size() == 0) {
                return wResult;
            }
            wFPCProductParameterList.removeIf(p -> p.StationID == null || p.StationID.size() <= 0);
            if (wFPCProductParameterList == null || wFPCProductParameterList.size() == 0) {
                return wResult;
            }
            //过滤掉该工序下的工位参数
            List<FPCProductParameter> wFilterList = new ArrayList<>();
            for (FPCProductParameter fpcProductParameter : wFPCProductParameterList) {
                if (wFPCRoutePartPoint.StationID.stream().anyMatch(p -> fpcProductParameter.StationID.stream().anyMatch(q -> q.intValue() == p.intValue()))) {
                    wFilterList.add(fpcProductParameter);
                }
            }
            if (wFilterList.size() <= 0) {
                return wResult;
            }

            wFPCProductParameterList = wFilterList;

            //③查询工序参数
            wParams.clear();
            wParams.put("RoutePartPointID", wRoutePartPointID);
            wParams.put("ProductParameter", wFPCParamType.getValue());
            List<FPCRoutePartPointParameter> wFPCRoutePartPointParameterList =
                    mFPCRoutePartPointParameterService.SelectPOList(wLoginUser, wParams, Pagination.getNewMaxSize(),
                            wErrorCode);
            //④产品参数剔除工序参数
            if (wRoutePartPointParamID > 0) {
                wFPCRoutePartPointParameterList.removeIf(p -> p.ID == wRoutePartPointParamID);
            }
            wFPCProductParameterList.removeIf(p -> wFPCRoutePartPointParameterList.stream().anyMatch(q -> q.ProductParameter == p.ID));
            //⑤返回前端
            wResult.Result = wFPCProductParameterList;

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("FPC_QueryToAddList", e);
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> FPC_CleanUpDirtyData(BMSEmployee wLoginUser) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            //①查询RouteParent
            Map<String, Object> wParams = new HashMap<String, Object>();
            List<FPCRouteParent> fpcRouteParents = mFPCRouteParentService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            //②查询Route
            List<FPCRoute> fpcRoutes = mFPCRouteService.SelectPOList(wLoginUser, wParams, Pagination.getNewMaxSize(),
                    wErrorCode);
            //③查询RoutePart
            List<FPCRoutePart> fpcRouteParts = mFPCRoutePartService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            //④查询RoutePartPoint
            List<FPCRoutePartPoint> fpcRoutePartPoints = mFPCRoutePartPointService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            //⑤查询RouteStep
            List<FPCRouteStep> fpcRouteSteps = mFPCRouteStepService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            //⑥查询物料清单
//            List<MSSMaterial> mssMaterials = mMSSMaterialService.SelectPOList(wLoginUser, wParams,
//                    Pagination.getNewMaxSize(),
//                    wErrorCode);
            //⑦查询工序物料
            List<MSSBOMItem> mssbomItems = mMSSBOMItemService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            //⑧查询工序量器具
            List<FPCRouteMeasureTool> fpcRouteMeasureTools = mFPCRouteMeasureToolService.SelectPOList(wLoginUser,
                    wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            //⑨查询工序工装
            List<FPCRouteFrockTool> fpcRouteFrockTools = mFPCRouteFrockToolService.SelectPOList(wLoginUser,
                    wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            //①清理工艺路线
            List<FPCRoute> wFPCRouteDelete =
                    fpcRoutes.stream().filter(p -> p.BOPParentID > 0 && fpcRouteParents.stream().noneMatch(q -> q.ID == p.BOPParentID)).collect(Collectors.toList());
            if (wFPCRouteDelete.size() > 0) {
                FPCRouteDAO.getInstance().DeleteList(wLoginUser, wFPCRouteDelete, wErrorCode);
            }
            //②清理工艺
            List<FPCRoutePart> wFPCRoutePartDelete =
                    fpcRouteParts.stream().filter(p -> p.RouteID > 0 && fpcRoutes.stream().noneMatch(q -> q.ID == p.RouteID)).collect(Collectors.toList());
            if (wFPCRoutePartDelete.size() > 0) {
                FPCRoutePartDAO.getInstance().DeleteList(wLoginUser, wFPCRoutePartDelete, wErrorCode);
            }
            //③清理工序
            List<FPCRoutePartPoint> wFPCRoutePartPointDelete =
                    fpcRoutePartPoints.stream().filter(p -> p.RoutePartID > 0 && fpcRouteParts.stream().noneMatch(q -> q.ID == p.RoutePartID)).collect(Collectors.toList());
            if (wFPCRoutePartPointDelete.size() > 0) {
                FPCRoutePartPointDAO.getInstance().DeleteList(wLoginUser, wFPCRoutePartPointDelete, wErrorCode);
            }
            //④清理工步
            List<FPCRouteStep> wFPCRouteStepDelete =
                    fpcRouteSteps.stream().filter(p -> p.RoutePartPointID > 0 && fpcRoutePartPoints.stream().noneMatch(q -> q.ID == p.RoutePartPointID)).collect(Collectors.toList());
            if (wFPCRouteStepDelete.size() > 0) {
                FPCRouteStepDAO.getInstance().DeleteList(wLoginUser, wFPCRouteStepDelete, wErrorCode);
            }
            //⑤清理工序物料
            List<MSSBOMItem> wMSSBOMItemDelete =
                    mssbomItems.stream().filter(p -> p.RoutePartPointID > 0 && fpcRoutePartPoints.stream().noneMatch(q -> q.ID == p.RoutePartPointID)).collect(Collectors.toList());
            if (wMSSBOMItemDelete.size() > 0) {
                FPCRoutePartPointDAO.getInstance().DeleteBOMItemList(wLoginUser, wMSSBOMItemDelete, wErrorCode);
            }
            //⑥清理工序量器具
            List<FPCRouteMeasureTool> wFPCRouteMeasureToolDelete =
                    fpcRouteMeasureTools.stream().filter(p -> p.RoutePartPointID > 0 && fpcRoutePartPoints.stream().noneMatch(q -> q.ID == p.RoutePartPointID)).collect(Collectors.toList());
            if (wFPCRouteMeasureToolDelete.size() > 0) {
                FPCRoutePartPointDAO.getInstance().DeleteMeasureToolList(wLoginUser, wFPCRouteMeasureToolDelete,
                        wErrorCode);
            }
            //⑦清理工序工装
            List<FPCRouteFrockTool> wFPCRouteFrockToolDelete =
                    fpcRouteFrockTools.stream().filter(p -> p.RoutePartPointID > 0 && fpcRoutePartPoints.stream().noneMatch(q -> q.ID == p.RoutePartPointID)).collect(Collectors.toList());
            if (wFPCRouteFrockToolDelete.size() > 0) {
                FPCRoutePartPointDAO.getInstance().DeleteFrockToolList(wLoginUser, wFPCRouteFrockToolDelete,
                        wErrorCode);
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("FPC_CleanUpDirtyData", e);
        }
        return wResult;
    }

    //endregion
}
